Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2006-05-16 14:37:46


In boost/fusion/.../list/detail/at_impl.hpp

the apply is recursive; however, the only reason for the
recursion is to "find the right element type". The other
reason for apply is the same as that of the apply
in.../vector/detail/at_impl.hpp. "find the right element
type" in vector's at_impl is done with mpl::at. The
similarity between list and vector at_impl would be more
apparent if:

             template <typename Sequence, int N>
             struct elem_at_c
             {
                 typedef typename
                     mpl::eval_if<
                         mpl::bool_<N == 0>
                       , mpl::identity<typename Sequence::car_type>
                       , elem_at_c<typename Sequence::cdr_type, N-1>
>::type
                 type;
             };

were used to find the right element type. Then the frist part of
list::at_impl::apply would be:

             template <typename Sequence, typename N>
             struct apply
             {
                 typedef elem_at_c<Sequence, N::value> element;
                 typedef typename
                     mpl::eval_if<
                         is_const<Sequence>
                       , detail::cref_result<element>
                       , detail::ref_result<element>
>::type
                 type;

which is very similar to the counterpart in vector:

             template <typename Sequence, typename N>
             struct apply
             {
                 typedef mpl::at<typename Sequence::types, N> element;
                 typedef typename
                     mpl::eval_if<
                         is_const<Sequence>
                       , detail::cref_result<element>
                       , detail::ref_result<element>
>::type
                 type;


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk