Boost utility to get const value_type for const std containers?
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 ? Thanks, -Mostafa
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
On Mon, 05 Jul 2010 14:35:58 -0700, Marshall Clow
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
On Jul 5, 2010, at 2:50 PM, Mostafa wrote:
On Mon, 05 Jul 2010 14:35:58 -0700, Marshall Clow
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; };
Sorry -- I completely misread your posting. -- Marshall
participants (2)
-
Marshall Clow
-
Mostafa