mpl -> integral sequence wrappers -> wrapping enums ?
Hello MPL experts,
I'd like to use meta - vectors of integral constants defined as enums.
But unfortunately the code below does not compile.
<code>
#include <iostream>
#include
Hello MPL experts !
Stepping forward in dealing with a mpl::vector_c of enums I found it hard to determine the correct expression to 'mpl::find' an element within such a vector.
The code below compiles with gcc 3.3.3 and shows 5 different approaches, but only version 4,5 really find the correct iterator.
Version 1,2,3 return iterators pointing to the vectors end.
It would be helpful if someone more familiar with MPL's concepts could give some explanation, particularly about the aspects:
- Is there a solution using mpl::find instead of mpl::find_if
If not, why the difference between finding elements in mpl::vector and mpl::vector_c ?
- What is the difference between using integral wrappers:
boost::mpl::integral_c
Martin Pasdzierny writes:
Stepping forward in dealing with a mpl::vector_c of enums I found it hard to determine the correct expression to 'mpl::find' an element within such a vector. The code below compiles with gcc 3.3.3 and shows 5 different approaches, but only version 4,5 really find the correct iterator. Version 1,2,3 return iterators pointing to the vectors end. It would be helpful if someone more familiar with MPL's concepts could give some explanation, particularly about the aspects:
- Is there a solution using mpl::find instead of mpl::find_if
Yes (assuming that the sequence you are searching in satisfies
Integral Sequence Wrapper requirements):
typedef vector_c
If not, why the difference between finding elements in mpl::vector and mpl::vector_c ?
'find' uses *type equality* ('boost::is_same') to determine whether
the elements are the same, and from standpoint of the C++ compiler,
all these
integral_c
- What is the difference between using integral wrappers: boost::mpl::integral_c
> boost::mpl::int_<c>
See the above.
- And still the question from the previous posting: Can I (should I) tell mpl::vector_c I'm using my own enum type and not plain int ?
Not at the moment, see my earlier reply. HTH, -- Aleksey Gurtovoy MetaCommunications Engineering
Martin Pasdzierny writes:
I'd like to use meta - vectors of integral constants defined as enums. But unfortunately the code below does not compile.
<code> #include <iostream> #include
#include enum MY_ENUM {X,Y}; // (*) typedef boost::mpl::vector_c
my_vector_c; static const int size = boost::mpl::size ::value; int main(int argc, char** argv) { std::cout << "\nsize:" << size << "\n... bye" << std::endl; } </code>
After replacing line (*) with
typedef boost::mpl::vector_c
my_vector_c; the code compiles and runs fine, but this does not look type safe any more.
Any suggestions ?!
Martin,
There is not much you can do on a user side to make it work, but we'll look
into fixing this for the next release. Meanwhile, I'd suggest to go with
'vector_c
participants (2)
-
Aleksey Gurtovoy
-
Martin Pasdzierny