How to use mpl::for_each with mpl::map
Hi,
I'm trying to use the runtime mpl::for_each algorithm on an mpl::map
that I have which associates enumerated values to various types.
I want to be able to call a functor for each of the enumerated key
values in the mpl::map but can't get the syntax right, I get the
following compiler error with MSVC 9.0
c:\source\vendor\boost\1_38_0\boost\mpl\pair.hpp(43) : error C2039:
'first' : is not a member of 'boost::mpl::arg<1>'
Any help appreciated.
Mark.
#include <iostream>
#include <string>
#include
, mpl::pair< mpl::int_< Wednesday >, mpl::identity< int > >, mpl::pair< mpl::int_< Thursday >, mpl::identity< __int64 > >, mpl::pair< mpl::int_< Friday >, mpl::identity< char > >, mpl::pair< mpl::int_< Saturday >, mpl::identity< bool > >, mpl::pair< mpl::int_< Sunday >, mpl::identity< int > > _day_field_types;
// Returns the type for the associated enumeration template< int FIELD_ID > struct FieldTypeT : mpl::at< _day_field_types, mpl::int_< FIELD_ID >
::type {};
// Prints value struct printer { template< typename T > void operator()( const T& x ) { std::cout << x << std::endl; } }; int main() { // Print the associated type for the 'Tuesday' enumeration std::cout << typeid( FieldTypeT< Tuesday >::type ).name() << std::endl;; // Print the list of enumerations mpl::for_each< _day_field_types, mpl::key_type< mpl::map<>, mpl::_1 > >( printer() ); // Compiler error! }
Mark wrote:
int main() { // Print the associated type for the 'Tuesday' enumeration std::cout << typeid( FieldTypeT< Tuesday >::type ).name() << std::endl;;
// Print the list of enumerations mpl::for_each< _day_field_types, mpl::key_type< mpl::map<>, mpl::_1 > >( printer() ); // Compiler error! }
// Print the list of enumerations mpl::for_each < _day_field_types, typename mpl::lambda < mpl::key_type < _day_field_types , mpl::_1 > >::type >( printer() ); // No Compiler error!
Thanks!
I wasn't aware you needed the mpl::lambda<>.
Mark.
On Apr 23, 4:46 pm, Noah Roberts
Mark wrote:
int main() { // Print the associated type for the 'Tuesday' enumeration std::cout << typeid( FieldTypeT< Tuesday >::type ).name() << std::endl;;
// Print the list of enumerations mpl::for_each< _day_field_types, mpl::key_type< mpl::map<>, mpl::_1
>( printer() ); // Compiler error! }
// Print the list of enumerations mpl::for_each < _day_field_types, typename mpl::lambda < mpl::key_type < _day_field_types , mpl::_1 > >::type >( printer() ); // No Compiler error!
_______________________________________________ Boost-users mailing list Boost-us...@lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Mark
-
Noah Roberts