Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Front Page / Metafunctions / String Operations / c_str

c_str

Synopsis

template<
      typename Sequence
    >
struct c_str
{
    typedef unspecified type;
    static char const value[];
};

Description

c_str converts the Forward Sequence of Integral Constants Sequence into a null-terminated byte string containing an equivalent sequence.

Header

#include <boost/mpl/string.hpp>

Model of

Metafunction

Parameters

Parameter Requirement Description
Sequence Forward Sequence of Integral Constants A sequence to be converted into a null-terminated byte string.

Expression semantics

For any Forward Sequence of Integral Constants s,

c_str<s>::value;
Return type:

A null-terminated byte string.

Precondition:

size<s>::value <= BOOST_MPL_STRING_MAX_LENGTH.

Semantics:

Equivalent to

char const value[] = {
    at<s, 0>::type::value
  , ...
  , at<s, size<s>::value-1>::type::value
  , '\0'
};

Complexity

Sequence archetype Complexity
Forward Sequence Linear.

Example

typedef vector_c<char,'h','e','l','l','o'> hello;
assert( 0 == std::strcmp( c_str<hello>::value, "hello" ) );

See also

Forward Sequence, Integral Constant, string