Boost logo

Boost :

From: Marco (mrcekets_at_[hidden])
Date: 2007-04-19 08:17:35


On Thu, 19 Apr 2007 11:21:08 +0200, John Maddock <john_at_[hidden]>
wrote:

> Cromwell Enage wrote:
>> --- John Maddock wrote:
>>> Stjepan Rajko wrote:
>>>> So far, I've been using:
>>>>
>>>> template<typename T>
>>>> struct storable : public
>>>> boost::remove_const<typename
>>>> boost::remove_reference<T>::type > {};
>>
>> [snip]
>>
>>> Your code will only work for class types right? If
>>> that's an acceptable limitation then it will do
>>> what you want, or did you mean:
>>>
>>> template<typename T>
>>> struct storable
>>> {
>>> typedef typename boost::remove_const<typename
>>> boost::remove_reference<T>::type > type;
>>> };
>>
>> I thought both class definitions would be equivalent
>> from a user's perspective, e.g.:
>>
>> BOOST_STATIC_ASSERT((
>> boost::is_same<
>> storable<int const&>::type
>> , int
>> >::value
>> ));
>
> ???? There's no nested ::type member in the first version.
>
>> I've been using the first style (the one Stjepan
>> presented) on primitive types without problems.
>
> Don't you end up inheriting from the primitive type in that case????
>
> Confused yours, John.
>

Maybe there is only a qui pro quo:

form #1 isn't

template<typename T>
struct storable
   : public
     typename boost::remove_const
     <
         typename boost::remove_reference<T>::type
>::type
{};

that would imply storable<const int &> : public int

but it's

template<typename T>
struct storable
   : public
     boost::remove_const
     <
         typename boost::remove_reference<T>::type
>
{};

that leads to :
storable< const int & > : public boost::remove_const< const int >

and so: typename storable< const int & >::type is equal to int

Marco

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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