Random access to sequences

I read up on boost::mpl::at<...>. It's pretty cool, but I wanted to make it a little easier to use. I found it a little annoying to have to type out 'int_<...>' for the index number, so I created a struct to automate that feature: ========================== template<typename SEQ, int IDX> struct atIdx { typedef typename boost::mpl::at<SEQ, boost::mpl::int_<IDX> >::type type; }; ========================== With the struct above, you can do the following: ============================= typedef boost::mpl::vector<int, char, int> t; atIdx<t, 0>::type i; // This line is shorter than the one below: /* atIdx<t, boost::mpl::int_<0> >::type i; */ ============================= Is this feature already available in boost somewhere? If I've reinvented the wheel, I'll be happy to use an existing implementation... Thanks, --Steve Stephen Gross Case Western School of Medicine Cleveland, OH "By Grabthar's hammer, by the sons of Worvan, you shall be avenged." - Dr. Lazarus

Stephen Gross writes:
I read up on boost::mpl::at<...>. It's pretty cool, but I wanted to make it a little easier to use. I found it a little annoying to have to type out 'int_<...>' for the index number, so I created a struct to automate that feature:
========================== template<typename SEQ, int IDX> struct atIdx { typedef typename boost::mpl::at<SEQ, boost::mpl::int_<IDX> >::type type; }; ==========================
With the struct above, you can do the following:
============================= typedef boost::mpl::vector<int, char, int> t; atIdx<t, 0>::type i; // This line is shorter than the one below: /* atIdx<t, boost::mpl::int_<0> >::type i; */ =============================
Is this feature already available in boost somewhere? If I've reinvented the wheel, I'll be happy to use an existing implementation...
See http://www.boost.org/libs/mpl/doc/refmanual/at-c.html. -- Aleksey Gurtovoy MetaCommunications Engineering
participants (2)
-
Aleksey Gurtovoy
-
Stephen Gross