RE: cant i use mpl::contains to find members of list_c ??

I was trying to use mpl::contains with list_c and it always seems to return mpl::false_.
For example typedef mpl::list_c< int ,16,8 > mylist; typedef mpl::contains<mylist, mpl::int_<16> >::type tt;
I've run into this issue in the past as well, and I vaguely rememember seeing mpl::integral_c<long>'s being used somewhere along the way, instead of mpl::integral_c<int>'s as one would expect. I'm not sure if that is still the case, or whether I was decaffeinated, but I ended up fixing it by using the following work-around (pseudo-code): template<class Sequence, class Elem> struct contains : mpl::contains < Sequence, mpl::integral_c < mpl::front<Sequence>::value_type, Elem::value> > >{}; Which isn't pretty, but it got the job done. You basically get the value_type of the first element in the sequence, to make sure the base type of the integral_c you're looking for matches with the sequence. I'm hoping Alexsey or Dave will step in here and clarify this, as it has been a source of confusion for me as well. Regards, Jaap Suter

"Jaap Suter" <boost@jaapsuter.com> writes:
I was trying to use mpl::contains with list_c and it always seems to return mpl::false_.
For example typedef mpl::list_c< int ,16,8 > mylist; typedef mpl::contains<mylist, mpl::int_<16> >::type tt;
I've run into this issue in the past as well, and I vaguely rememember seeing mpl::integral_c<long>'s being used somewhere along the way, instead of mpl::integral_c<int>'s as one would expect.
You can expect that list_c to contain integral_c<int,16> and integral_c<int,8>, neither of which is the same type as int_<16>. I suggest you try a predicate like mpl::equal_to<_,_> with find_if: typedef not_< is_same< find_if<s,mpl::int_<16>, mpl::equal_to<_,_> >::type , end<s>::type > >::type r; HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Jaap Suter