Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost utility to get const value_type for const std containers?
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2010-07-05 17:35:58

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 );

This is not the way that I would write it, though, since it assumes that the pointer pFirst points to at least as many non-zero characters as are in the container. I would add some kind of checking to make sure the sequences were the same size, or maybe just check the sizes before (which is cheap for some containers) and return false if the sizes didn't match.

-- Marshall

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at