Reference information for mpl::for_each ?

(1) Where can I find reference information for mpl::for_each (I've looked around on the boost website and can't seem to find it). (2) Here's what I'm trying to do: I've got an mpl::vector. Given some type T, I want to loop across the vector and see if T is convertible to any of the types in the vector. I tried something like 'for_each<typelist, is_convertible<T, _1> >()' but my syntax is definitely wrong. Any ideas? Thanks in advance, --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 <mrstephengross@hotmail.com> wrote:
(1) Where can I find reference information for mpl::for_each (I've looked around on the boost website and can't seem to find it).
(2) Here's what I'm trying to do: I've got an mpl::vector. Given some type T, I want to loop across the vector and see if T is convertible to any of the types in the vector. I tried something like 'for_each<typelist, is_convertible<T, _1> >()' but my syntax is definitely wrong. Any ideas?
Thanks in advance, --Steve
Stephen Gross Case Western School of Medicine Cleveland, OH
You can use fold in this case. So it could be something like this: template< typename Sequence, typename T > struct find_convertible : fold< Sequence, void_, if_< is_void_< _1 >, is_convertible< T, _2 >, _1 > {}; is_convertible shall return void_ in case it cannot convert for this to work (you can use different type, but need to change initial value and if statement accordingly). I made a suggestion to make such algorithm available in the lib. But it is possible it can be simply implemented through already existing algorithms. Regards, Vyacheslav

"Stephen Gross" <mrstephengross@hotmail.com> writes:
(1) Where can I find reference information for mpl::for_each (I've looked around on the boost website and can't seem to find it).
Seems to be missing. Aleksey?
(2) Here's what I'm trying to do: I've got an mpl::vector. Given some type T, I want to loop across the vector and see if T is convertible to any of the types in the vector.
If you want a compile-time result, for_each isn't going to help you. for_each is designed to invoke a *runtime* function on each type in a sequence. Maybe template <class Sequence, class T> struct contains_convertible_type : mpl::not_< boost::is_same< typename mpl::find_if< type_sequence , boost::is_convertible<T,_1> >::type , typename mpl::end<Sequence>::type > > {}; ?? HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com

Stephen Gross writes:
(1) Where can I find reference information for mpl::for_each (I've looked around on the boost website and can't seem to find it).
I'm afraid it's missing from the reference docs.
(2) Here's what I'm trying to do: I've got an mpl::vector. Given some type T, I want to loop across the vector and see if T is convertible to any of the types in the vector.
!is_same< find_if< seq, is_convertible<T, _1> >::type , end<seq>::type >::value ?
I tried something like 'for_each<typelist, is_convertible<T, _1>
()' but my syntax is definitely wrong. Any ideas?
Unless I misunderstood your needs, something like the above should work for you. 'for_each' is the only run-time iteration algorithm in the library, and it's probably not what you want here. In absense of better docs at the moment, you can read chapter 4 of http://www.boost.org/libs/mpl/doc/paper/mpl_paper.pdf to get an idea what's 'for_each' is about. HTH, -- Aleksey Gurtovoy MetaCommunications Engineering
participants (4)
-
Aleksey Gurtovoy
-
David Abrahams
-
Stephen Gross
-
Vyacheslav Kononenko