Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost utility to get const value_type for const std containers?
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2010-07-05 17:50:40


On Mon, 05 Jul 2010 14:35:58 -0700, Marshall Clow <mclow.lists_at_[hidden]>
wrote:

> On Jul 5, 2010, at 2:10 PM, Mostafa wrote:
>
>> Hi all,
>>
>> Is there a boost utility that will return the "correct" value_type for
>> std containers? i.e., for:
>>
>> typedef std::vector<char> const CharVector;
>>
>> is there SomeBoostUtility<CharVector>::Type == char const ?
>
> I don't know of one, but this should work:
>
> template <class Container>
> bool equal_to_string ( const Container &c, const typename
> Container::value_type *pFirst ) {
> return std::equal ( c.begin (), c.end (), pFirst );
> }

Thanks, I was actually looking for something that will return either a
const or non-const qualified value_type for the complimentary qualified
container type. Something like this:

template <typename T>
struct StdContainerValue
{
     typedef typename T::value_type Type;
};

template <typename T>
struct StdContainerValue<T const>
{
     typedef typename T::value_type const Type;
};

-Mostafa


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