• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. Metafunctions/String Operations//c_str |10
2
3
4c_str
5=====
6
7Synopsis
8--------
9
10.. parsed-literal::
11
12    template<
13          typename Sequence
14        >
15    struct c_str
16    {
17        typedef |unspecified| type;
18        static char const value[];
19    };
20
21
22Description
23-----------
24
25``c_str`` converts the |Forward Sequence| of |Integral Constant|\ s ``Sequence``
26into a null-terminated byte string containing an equivalent sequence.
27
28
29Header
30------
31
32.. parsed-literal::
33
34    #include <boost/mpl/string.hpp>
35
36
37Model of
38--------
39
40|Metafunction|
41
42
43Parameters
44----------
45
46+---------------+---------------------------+-----------------------------------------------+
47| Parameter     | Requirement               | Description                                   |
48+===============+===========================+===============================================+
49| ``Sequence``  | |Forward Sequence| of     | A sequence to be converted into a             |
50|               | |Integral Constant|\ s    | null-terminated byte string.                  |
51+---------------+---------------------------+-----------------------------------------------+
52
53
54Expression semantics
55--------------------
56
57.. compound::
58    :class: expression-semantics
59
60    For any |Forward Sequence| of |Integral Constant|\ s ``s``,
61
62    .. parsed-literal::
63
64        c_str<s>::value;
65
66    :Return type:
67        A null-terminated byte string.
68
69    :Precondition:
70        ``size<s>::value <= BOOST_MPL_STRING_MAX_LENGTH``.
71
72    :Semantics:
73        Equivalent to
74
75        .. parsed-literal::
76
77           char const value[] = {
78               at<s, 0>::type::value
79             , ...
80             , at<s, size<s>::value-1>::type::value
81             , '\\0'
82           };
83
84Complexity
85----------
86
87+-------------------------------+-----------------------------------+
88| Sequence archetype            | Complexity                        |
89+===============================+===================================+
90| |Forward Sequence|            | Linear.                           |
91+-------------------------------+-----------------------------------+
92
93Example
94-------
95
96.. parsed-literal::
97
98    typedef vector_c<char,'h','e','l','l','o'> hello;
99    assert( 0 == std::strcmp( c_str<hello>::value, "hello" ) );
100
101See also
102--------
103
104|Forward Sequence|, |Integral Constant|, |string|
105
106
107.. copyright:: Copyright �  2009 Eric Niebler
108   Distributed under the Boost Software License, Version 1.0. (See accompanying
109   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
110