[fusion] list/detail/at_impl.hpp, Suggest recrusive elem_at_c instead of recursive apply

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;

Larry Evans wrote:
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;
Looks good to me. Do you have a patch? Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

On 05/17/2006 01:10 AM, Joel de Guzman wrote:
Larry Evans wrote: [snip]
type" in vector's at_impl is done with mpl::at. The similarity between list and vector at_impl would be more apparent if: [snip suggested changes] Looks good to me. Do you have a patch? Well, I've got a rcsdiff -c between the two versions. The command was:
rcsdiff -c -r1.1 -r1.2 at_impl.hpp>at_impl.hpp.diff =================================================================== RCS file: RCS/at_impl.hpp,v retrieving revision 1.1 retrieving revision 1.2 diff -c -r1.1 -r1.2 and the resulting diff should be attached. I'm on linux; so, the diff includes some CRLF char which you might not like. The 1.1 version is the one from the zip file mentioned in the original fusion review post. IOW, it's not from: http://spirit.sourceforge.net/dl_more/fusion_v2_review/ but I assume there's no difference between the original zip and fusion_v2_review files. *** at_impl.hpp 2006/05/16 16:53:31 1.1 --- at_impl.hpp 2006/05/16 18:26:18 1.2 *************** *** 26,50 **** template <> struct at_impl<cons_tag> { ! template <typename Sequence, typename N> ! struct apply { - typedef typename - mpl::eval_if< - is_const<Sequence> - , add_const<typename Sequence::cdr_type> - , mpl::identity<typename Sequence::cdr_type> - >::type - cdr_type; - typedef typename mpl::eval_if< ! mpl::bool_<N::value == 0> , mpl::identity<typename Sequence::car_type> ! , apply<cdr_type, mpl::int_<N::value-1> > ! > ! element; typedef typename mpl::eval_if< is_const<Sequence> --- 26,47 ---- template <> struct at_impl<cons_tag> { ! 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; ! }; + template <typename Sequence, typename N> + struct apply + { + typedef elem_at_c<Sequence, N::value> element; typedef typename mpl::eval_if< is_const<Sequence> *************** *** 52,58 **** , detail::ref_result<element> >::type type; ! template <typename Cons, int N2> static type call(Cons& s, mpl::int_<N2>) --- 49,55 ---- , detail::ref_result<element> >::type type; ! template <typename Cons, int N2> static type call(Cons& s, mpl::int_<N2>)

On 05/17/06 01:10, Joel de Guzman wrote:
Larry Evans wrote:
In boost/fusion/.../list/detail/at_impl.hpp [snip] Looks good to me. Do you have a patch? Attached is a recent svn diff and the command used to produce it. Is there anything else needed to make this change?
-regards, Larry cd ~/prog_dev/boost-svn/ro/trunk/boost/fusion/container/list/detail/ svn diff at_impl.hpp > x.diff Compilation finished at Wed Oct 24 13:40:21
participants (2)
-
Joel de Guzman
-
Larry Evans