Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2007-01-04 10:03:42


Johan,

sorry, I have somehow overseen your or misunderstood question.

You can implement smth like this:

template <class T>
struct Type2String
{
    typedef T type;
    static const std::string type_name;
};

const std::string Type2String<T>::type_name(type_id(T).name());

template<class T>
struct pair_gen
{
    typedef mpl::pair< T, Type2String<T> > type;
};

typedef mpl::map<pair_gen<int>::type, pair_gen<double>::type, pair_gen<SomeClass>::type> SomeMap;

With Kind Regards,

Ovanes

On Thu, January 4, 2007 13:47, Ovanes Markarian wrote:
> Johan,
>
> can you please be more specific? MPL has a map construct mpl::map it can be used like:
>
>
> typedef mpl::map<mpl::pair<int,double>, mpl::pair<float, SomeOtherType> > MyMap;
>
> BOOST_MPL_ASSERT(( is_same<mpl::at<MyMap, int>::type, double> ));
>
>
>
> You can also map a discriminator value to some type:
>
> typedef mpl::map< mpl::pair<mpl::int_<0>, double>, mpl::pair<mpl::int_<1>, int> > MyMap2;
>
> BOOST_MPL_ASSERT(( is_same<mpl::at<MyMap, mpl::int_<0> >::type, double> ));
> BOOST_MPL_ASSERT(( is_same<mpl::at<MyMap, mpl::int_<1> >::type, int> ));
>
>
>
> But I do not know if it is what you were looking for.
>
> With Kind Regards,
>
> Ovanes Markarian
>
>
>
> On Thu, January 4, 2007 13:11, Johan Torp wrote:
>> What is the best practice for creating a map from a type to a value?
>>
>> Currently I do it like this:
>> =====================================
>> struct SomeMap
>> {
>> template<typename T> static const std::string& LookUp();
>> };
>>
>> template <> const std::string& SomeMap::LookUp<int>()
>> {
>> static const std::string s("int");
>> return s;
>> }
>> =====================================
>> ...but this seems far from optimal.
>>
>> --
>> System Developer
>> TouchTable AB
>> Tel: +46 (0)31 773 68 12
>> johan.torp_at_[hidden]
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net