Boost logo

Boost :

Subject: Re: [boost] [mpl] mpl::c_str fails for mpl::push_back
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-11-08 12:01:58


----- Original Message -----
From: "Aleksey Gurtovoy" <agurtovoy_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Monday, November 08, 2010 11:06 AM
Subject: Re: [boost] [mpl] mpl::c_str fails for mpl::push_back

> A more general approach would be something like this (untested):
>
>
> BOOST_MPL_HAS_XXX_TRAIT_DEF( value_type )
>
> template< bool, typename X > struct value_type_impl
> {
> typedef typename X::value_type type;
> }
>
> template< typename X > struct value_type
> : value_type_impl< has_value_type<X>::value, X >
> {
> };
>
> template< typename X > struct value_type_impl<false,X>
> {
> typedef typename value_type< typename front<X>::type >::type type;
> };

Yes this will be more general. I will add that as the sequence can be heterogeneous we would choose as value_type of a Integral Sequece wrapper as the common_type of all the element's value_type. If some of the Seq elements are not integral wrappers or there is not a common type, value_type<Seq> will not compile.

A complementay possibility is to extend the c_str class with a new template parameter ValueType (all the sequence's member should be convertible to it). ValueType could default to Sequence::value_type or value_type<Sequence>.

const char16_t* u16str = c_str<Seq, char16_t>::value;

This will work if each element on Seq is convertible to char16_t. And the following will works as before

const char* str = c_str<String>::value;

>> Is there a possibility to add this trait to Boost.MPL and the
>> corresponding specialization and move the c_str function to a standalone
>> file ?
>
> If it's OK with Eric, I'd be happy to accept the patch.

I'll prepare a patch with the c_str parameter extension in a separated file, as it should not depend any more on mpl::string and could work with other sequences and the value_type trait in another file. Let me know if there is someting wrong.

Best,
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk