Boost logo

Boost Users :

From: Markus Werle (yg-boost-users_at_[hidden])
Date: 2003-06-25 03:08:11


Jaakko Jarvi wrote:

> std::for_each(M.begin(), M.end(),
> std::cout << l::bind(select2nd(), l::_1) << " ");

Well, that's too complicated ;-)
_binding_ to a function or functor is the approach
I wanted to avoid.

I think that select1st and select2nd (or - to be generic - select<n>)
could be directly supported by boost::lambda.
It's so common to have a list/vector of tuples or a std::map
(yes, its a request for a feature ;-))

I tried to write something taking ll_static_cast as an example,
but failed to quickly understand the requirements
and semantics of lambda_functor*

Could You correct/complete the code below?
I could not figure out how select2nd_action::apply
gets its RET defined :-(
Is there some documentation on the functor conventions
or on how to extend LL?

class select2nd_action
{
public:
  template<class RET, class Arg1>
  static RET apply(Arg1 &a1) {
    return a1.second;
  }
};

template <class Arg1>
inline const lambda_functor<
  lambda_functor_base<
    action<1, select2nd_action >,
    tuple<typename const_copy_argument <const Arg1>::type>
>
>
ll_select2nd(const Arg1& a1) {
  return
    lambda_functor_base<
      action<1, select2nd_action >,
      tuple<typename const_copy_argument <const Arg1>::type>
>
  ( tuple<typename const_copy_argument <const Arg1>::type>(a1));
}

best regards,

Markus

-- 
Build your own Expression Template Library with Daixtrose!
Visit http://daixtrose.sourceforge.net/ 

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net