1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
   | struct no_arg{};
 
template <typename function, 
          typename result_type = boost::function_traits<function>::result_type,
          typename arg1_type = boost::function_traits<function>::arg1_type,
	  std::size_t arity = boost::function_traits<function>::arity>
struct arity_trait;
 
template <typename unary_function, 
          typename result_type = boost::function_traits<unary_function>::result_type,
	  typename arg1_type = boost::function_traits<unary_function>::arg1_type,
	  std::size_t arity = boost::function_traits<unary_function>::arity>
struct arity_trait<unary_function, result_type, arg1_type, 1>
{
  typedef unary_function type;
 
  template <typename bind_arg>
  static type bind_function(unary_function f, bind_arg&)
  {
    return f;
  }
};
 
template <typename binary_function, 
          typename result_type = boost::function_traits<binary_function>::result_type,
	  typename arg1_type = boost::function_traits<binary_function>::arg1_type,
	  std::size_t arity = boost::function_traits<binary_function>::arity>
struct arity_trait<binary_function, result_type, arg1_type, 2>
{
  typedef boost::function<result_type(arg1_type)> type;
 
  template <typename bind_arg>
  static type bind_function(binary_function f, bind_arg& arg)
  {
    return boost::bind(f(), boost::bind(deref<bind_arg>, arg));
  }
};
 
template <typename function, typename iterator>
struct condition_trait
{
  template <typename base_iterator, typename bind_arg>
  static iterator<function, base_iterator> begin(base_iterator b, base_iterator e, bind_arg &arg)
  {
    typedef arity_trait<function> binding;
    return iterator<binding::type, base_iterator>(binding::bind_function(function(), arg), b, e);
  }
 
  template <typename base_iterator, typename bind_arg>
  static iterator<function, base_iterator> end(base_iterator b, base_iterator e, bind_arg &arg)
  {
    typedef arity_trait<function> binding;
    return iterator<binding::type, base_iterator>(binding::bind_function(function(), arg), e, e);
  }
};
 
template <typename condition, typename iterator>
struct condition_trait<no_arg, iterator>
{
  template <typename base_iterator, typename bind_arg>
  static base_iterator& begin(base_iterator &b, base_iterator &, bind_arg&) 
  {
    return b;
  }
 
  template <typename base_iterator, typename bind_arg>
  static base_iterator& end(base_iterator &e, bind_arg&) 
  {
    return e;
  }
} | 
Partager