<commit_before>#ifndef SAUCE_INTERNAL_IMPLICIT_BINDINGS_H_
#define SAUCE_INTERNAL_IMPLICIT_BINDINGS_H_

#include <string>

#include <sauce/exceptions.h>
#include <sauce/injector.h>
#include <sauce/memory.h>
#include <sauce/provider.h>
#include <sauce/scopes.h>
#include <sauce/internal/resolved_binding.h>
#include <sauce/internal/injection_binding.h>
#include <sauce/internal/bindings.h>
#include <sauce/internal/injections/all.h>
#include <sauce/internal/key.h>

namespace sauce {
namespace internal {

struct ImplicitBindings;

typedef Bindings<ImplicitBindings> ConcreteBindings;

template<typename ImplicitInjection_>
struct ImplicitBindingTraits {
  typedef ImplicitInjection_ ImplicitInjection;
  typedef typename ImplicitInjection::Dependency Dependency;
  typedef typename ImplicitInjection::InjectionPtr InjectionPtr;
  typedef typename ResolvedBinding<Dependency>::BindingPtr BindingPtr;
};

/**
 * Attempts to supply a Binding when the given Dependency is not found.
 */
template<typename Dependency>
struct ImplicitBinding {
  typedef sauce::shared_ptr<ResolvedBinding<Dependency> > BindingPtr;

  /**
   * Attempt to supply a (unknown) Binding at provision time.
   */
  static BindingPtr get(ConcreteBindings const &, std::string name) {
    throw UnboundExceptionFor<Dependency>(name);
  }

};

/**
 * Attempts to supply a Binding when none is found for a dependency.
 */
struct ImplicitBindings {

  /**
   * Attempt to supply a (unknown) Binding at provision time.
   */
  template<typename Dependency>
  sauce::shared_ptr<ResolvedBinding<Dependency> > get(
    ConcreteBindings const & bindings, std::string name) const {
    return ImplicitBinding<Dependency>::get(bindings, name);
  }

};

/**
 * The implicit Injector binding.
 */
template<>
struct ImplicitBinding<Named<Injector, Unnamed> >: ImplicitBindingTraits<inj::InjectorInjection> {
  static BindingPtr get(ConcreteBindings const &, std::string) {
    // TODO: barf unless name == unnamed()?
    InjectionPtr injection(new ImplicitInjection());
    BindingPtr binding(new InjectionBinding<Dependency, NoScope>(injection));
    return binding;
  }
};

/**
 * The implicit Provider binding for bound dependencies.
 */
template<typename ProvidedDependency, typename Name>
struct ImplicitBinding<Named<Provider<ProvidedDependency>, Name> > {
  typedef ImplicitBindingTraits<inj::ImplicitProviderInjection<ProvidedDependency, Name> > Traits;
  typedef typename Traits::ImplicitInjection ImplicitInjection;<commit_msg>Reject dynamic-name implicit injector bindings.<commit_after>#ifndef SAUCE_INTERNAL_IMPLICIT_BINDINGS_H_
#define SAUCE_INTERNAL_IMPLICIT_BINDINGS_H_

#include <string>

#include <sauce/exceptions.h>
#include <sauce/injector.h>
#include <sauce/memory.h>
#include <sauce/provider.h>
#include <sauce/scopes.h>
#include <sauce/internal/resolved_binding.h>
#include <sauce/internal/injection_binding.h>
#include <sauce/internal/bindings.h>
#include <sauce/internal/injections/all.h>
#include <sauce/internal/key.h>

namespace sauce {
namespace internal {

struct ImplicitBindings;

typedef Bindings<ImplicitBindings> ConcreteBindings;

template<typename ImplicitInjection_>
struct ImplicitBindingTraits {
  typedef ImplicitInjection_ ImplicitInjection;
  typedef typename ImplicitInjection::Dependency Dependency;
  typedef typename ImplicitInjection::InjectionPtr InjectionPtr;
  typedef typename ResolvedBinding<Dependency>::BindingPtr BindingPtr;
};

/**
 * Attempts to supply a Binding when the given Dependency is not found.
 */
template<typename Dependency>
struct ImplicitBinding {
  typedef sauce::shared_ptr<ResolvedBinding<Dependency> > BindingPtr;

  /**
   * Attempt to supply a (unknown) Binding at provision time.
   */
  static BindingPtr get(ConcreteBindings const &, std::string name) {
    throw UnboundExceptionFor<Dependency>(name);
  }

};

/**
 * Attempts to supply a Binding when none is found for a dependency.
 */
struct ImplicitBindings {

  /**
   * Attempt to supply a (unknown) Binding at provision time.
   */
  template<typename Dependency>
  sauce::shared_ptr<ResolvedBinding<Dependency> > get(
    ConcreteBindings const & bindings, std::string name) const {
    return ImplicitBinding<Dependency>::get(bindings, name);
  }

};

/**
 * The implicit Injector binding.
 */
template<>
struct ImplicitBinding<Named<Injector, Unnamed> >: ImplicitBindingTraits<inj::InjectorInjection> {
  static BindingPtr get(ConcreteBindings const &, std::string name) {
    if (name != unnamed()) {
      throw UnboundExceptionFor<Named<Injector, Unnamed> >(name);
    }
    InjectionPtr injection(new ImplicitInjection());
    BindingPtr binding(new InjectionBinding<Dependency, NoScope>(injection));
    return binding;
  }
};

/**
 * The implicit Provider binding for bound dependencies.
 */
template<typename ProvidedDependency, typename Name>
struct ImplicitBinding<Named<Provider<ProvidedDependency>, Name> > {
  typedef ImplicitBindingTraits<inj::ImplicitProviderInjection<ProvidedDependency, Name> > Traits;
  typedef typename Traits::ImplicitInjection ImplicitInjection;
{'fraction_non_alphanumeric': 0.10118110236220472, 'fraction_numerical': 0.0, 'mean_word_length': 5.875507442489851, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2536529', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1520, 'n_words': 358}