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 >
boost::mpl::int_<c>
- 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 ?
regards, Martin.
<CODE>
#include <iostream>
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace boost::mpl::placeholders;
enum MY_ENUM {X=12,Y=24,Z=36};
typedef boost::mpl::vector_c my_vector_c;
template struct test {
static const MY_ENUM value = c;
typedef typename boost::mpl::find::type c_iter_1;
typedef typename boost::mpl::find >::type c_iter_2;
typedef typename boost::mpl::find >::type c_iter_3;
typedef typename boost::mpl::find_if >::type c_iter_4;
typedef typename boost::mpl::find_if > >::type c_iter_5;
// these 3 lines are only for showing the end iterators position:
typedef typename boost::mpl::end<MyEnums>::type end_iter;
typedef typename end_iter::pos end_pos_t;
static const int end_pos = end_pos_t::value;
};
int main(int argc, char** argv) {
std::cout << "\ntest<.,X>::end_pos:" << test::end_pos << std::endl;
std::cout << "\ntest<.,Y>::c_iter_1::pos::value:" << test::c_iter_1::pos::value << std::endl;
std::cout << "\ntest<.,Y>::c_iter_2::pos::value:" << test::c_iter_2::pos::value << std::endl;
std::cout << "\ntest<.,Y>::c_iter_3::pos::value:" << test::c_iter_3::pos::value << std::endl;
std::cout << "\ntest<.,Y>::c_iter_4::pos::value:" << test::c_iter_4::pos::value << std::endl;
std::cout << "\ntest<.,Y>::c_iter_5::pos::value:" << test::c_iter_5::pos::value << std::endl;
}
</CODE>