1
0
forked from boostorg/mpl

Merged revisions 52208,52241,52271,52314-52315,52317,52361,52542,52579 via svnmerge from

https://svn.boost.org/svn/boost/trunk


[SVN r53838]
This commit is contained in:
Eric Niebler
2009-06-13 01:03:44 +00:00
parent 54bf81da35
commit 4599fe865f
13 changed files with 1512 additions and 0 deletions

View File

@@ -71,6 +71,7 @@ Models
* |bool_| * |bool_|
* |int_| * |int_|
* |long_| * |long_|
* |char_|
* |integral_c| * |integral_c|

View File

@@ -0,0 +1,52 @@
.. Macros/Configuration//BOOST_MPL_LIMIT_STRING_SIZE |65
.. Copyright Eric Niebler 2009.
.. Distributed under the Boost
.. Software License, Version 1.0. (See accompanying
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
BOOST_MPL_LIMIT_STRING_SIZE
===========================
Synopsis
--------
.. parsed-literal::
#if !defined(BOOST_MPL_LIMIT_STRING_SIZE)
# define BOOST_MPL_LIMIT_STRING_SIZE \\
|idic| \\
/\*\*/
#endif
Description
-----------
``BOOST_MPL_LIMIT_STRING_SIZE`` is an overridable configuration macro regulating
the maximum arity of the ``string``\ 's |variadic forms|. In this
implementation of the library, ``BOOST_MPL_LIMIT_STRING_SIZE`` has a default value
of 32. To override the default limit, define ``BOOST_MPL_LIMIT_STRING_SIZE`` to
the desired maximum arity before including any library header.
Example
-------
.. parsed-literal::
#define BOOST_MPL_LIMIT_STRING_SIZE 8
``#``\ include <boost/mpl/string.hpp>
using namespace boost::mpl;
typedef string<'a'> s_1;
typedef string<'abcd','efgh'> s_8;
// typedef string<'abcd','efgh','i'> s_9; // error!
See also
--------
|Configuration|, |BOOST_MPL_LIMIT_VECTOR_SIZE|

108
doc/src/refmanual/c_str.rst Normal file
View File

@@ -0,0 +1,108 @@
.. Metafunctions/String Operations//c_str |10
.. Copyright Eric Niebler 2009.
.. Distributed under the Boost
.. Software License, Version 1.0. (See accompanying
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
c_str
=====
Synopsis
--------
.. parsed-literal::
template<
typename Sequence
>
struct c_str
{
typedef |unspecified| type;
static char const value[];
};
Description
-----------
``c_str`` converts the |Forward Sequence| of |Integral Constant|\ s ``Sequence``
into a null-terminated byte string containing an equivalent sequence.
Header
------
.. parsed-literal::
#include <boost/mpl/string.hpp>
Model of
--------
|Metafunction|
Parameters
----------
+---------------+---------------------------+-----------------------------------------------+
| Parameter | Requirement | Description |
+===============+===========================+===============================================+
| ``Sequence`` | |Forward Sequence| of | A sequence to be converted into a |
| | |Integral Constant|\ s | null-terminated byte string. |
+---------------+---------------------------+-----------------------------------------------+
Expression semantics
--------------------
.. compound::
:class: expression-semantics
For any |Forward Sequence| of |Integral Constant|\ s ``s``,
.. parsed-literal::
c_str<s>::value;
:Return type:
A null-terminated byte string.
:Precondition:
``size<s>::value <= BOOST_MPL_STRING_MAX_LENGTH``.
:Semantics:
Equivalent to
.. parsed-literal::
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
-------
.. parsed-literal::
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|

View File

@@ -0,0 +1,89 @@
.. Data Types/Numeric//char_ |60
.. Copyright Eric Niebler 2009.
.. Distributed under the Boost
.. Software License, Version 1.0. (See accompanying
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
char\_
======
Synopsis
--------
.. parsed-literal::
template<
char N
>
struct char\_
{
// |unspecified|
// ...
};
Description
-----------
An |Integral Constant| wrapper for ``char``.
Header
------
.. parsed-literal::
#include <boost/mpl/char.hpp>
Model of
--------
|Integral Constant|
Parameters
----------
+---------------+-------------------------------+---------------------------+
| Parameter | Requirement | Description |
+===============+===============================+===========================+
| ``N`` | A character constant | A value to wrap. |
+---------------+-------------------------------+---------------------------+
Expression semantics
--------------------
|Semantics disclaimer...| |Integral Constant|.
For arbitrary character constant ``c``:
+-------------------+-----------------------------------------------------------+
| Expression | Semantics |
+===================+===========================================================+
| ``char_<c>`` | An |Integral Constant| ``x`` such that ``x::value == c`` |
| | and ``x::value_type`` is identical to ``char``. |
+-------------------+-----------------------------------------------------------+
Example
-------
.. parsed-literal::
typedef char_<'c'> c;
BOOST_MPL_ASSERT(( is_same< c::value_type, char > ));
BOOST_MPL_ASSERT(( is_same< c::type, c > ));
BOOST_MPL_ASSERT(( is_same< next< c >::type, char_<'d'> > ));
BOOST_MPL_ASSERT(( is_same< prior< c >::type, char_<'b'> > ));
BOOST_MPL_ASSERT_RELATION( (c::value), ==, 'c' );
assert( c() == 'c' );
See also
--------
|Data Types|, |Integral Constant|, |int_|, |size_t|, |integral_c|

View File

@@ -23,6 +23,7 @@ Metafunctions/Comparisons
Metafunctions/Logical Operations Metafunctions/Logical Operations
Metafunctions/Bitwise Operations Metafunctions/Bitwise Operations
Metafunctions/Trivial Metafunctions/Trivial
Metafunctions/String Operations
Metafunctions/Miscellaneous Metafunctions/Miscellaneous
Data Types Data Types
Data Types/Concepts Data Types/Concepts

View File

@@ -0,0 +1,135 @@
.. Sequences/Classes//string |100
.. Copyright Eric Niebler 2009.
.. Distributed under the Boost
.. Software License, Version 1.0. (See accompanying
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
string
======
Description
-----------
``string`` is a |variadic|, `bidirectional`__, `extensible`__ |Integral Sequence Wrapper| of
characters that supports amortized constant-time insertion and removal of elements at both ends,
and linear-time insertion and removal of elements in the middle. The parameters to ``string``
are multi-character literals, giving a somewhat readable syntax for compile-time strings.
``string`` can also be an argument to the ``c_str`` metafunction, which generates a
null-terminated character array that facilitates interoperability with runtime string
processing routines.
__ `Bidirectional Sequence`_
__ `Extensible Sequence`_
Header
------
+-------------------+-------------------------------------------------------+
| Sequence form | Header |
+===================+=======================================================+
| Variadic | ``#include <boost/mpl/string.hpp>`` |
+-------------------+-------------------------------------------------------+
Model of
--------
* |Integral Sequence Wrapper|
* |Variadic Sequence|
* |Bidirectional Sequence|
* |Extensible Sequence|
* |Back Extensible Sequence|
* |Front Extensible Sequence|
Expression semantics
--------------------
In the following table, ``s`` is an instance of ``string``, ``pos`` and ``last`` are iterators
into ``s``, ``r`` is a |Forward Sequence| of characters, ``n`` and ``x`` are |Integral Constant|\ s,
and |c1...cn| are arbitrary (multi-)characters.
+---------------------------------------+-----------------------------------------------------------+
| Expression | Semantics |
+=======================================+===========================================================+
| .. parsed-literal:: | ``string`` of characters |c1...cn|; see |
| | |Variadic Sequence|. |
| string<|c1...cn|> | |
+---------------------------------------+-----------------------------------------------------------+
| .. parsed-literal:: | Identical to ``string<``\ |c1...cn|\ ``>``; |
| | see |Variadic Sequence|. |
| string<|c1...cn|>::type | |
+---------------------------------------+-----------------------------------------------------------+
| ``begin<s>::type`` | An iterator pointing to the beginning of ``s``; |
| | see |Bidirectional Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``end<s>::type`` | An iterator pointing to the end of ``s``; |
| | see |Bidirectional Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``size<s>::type`` | The size of ``s``; see |Bidirectional Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``empty<s>::type`` | |true if and only if| the sequence is empty; |
| | see |Bidirectional Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``front<s>::type`` | The first element in ``s``; see |
| | |Bidirectional Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``back<s>::type`` | The last element in ``s``; see |
| | |Bidirectional Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``insert<s,pos,x>::type`` | A new ``string`` of following elements: |
| | [``begin<s>::type``, ``pos``), ``x``, |
| | [``pos``, ``end<s>::type``); see |Extensible Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``insert_range<s,pos,r>::type`` | A new ``string`` of following elements: |
| | [``begin<s>::type``, ``pos``), |
| | [``begin<r>::type``, ``end<r>::type``) |
| | [``pos``, ``end<s>::type``); see |Extensible Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``erase<s,pos>::type`` | A new ``string`` of following elements: |
| | [``begin<s>::type``, ``pos``), |
| | [``next<pos>::type``, ``end<s>::type``); see |
| | |Extensible Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``erase<s,pos,last>::type`` | A new ``string`` of following elements: |
| | [``begin<s>::type``, ``pos``), |
| | [``last``, ``end<s>::type``); see |Extensible Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``clear<s>::type`` | An empty ``string``; see |Extensible Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``push_back<s,x>::type`` | A new ``string`` of following elements: |
| | |begin/end<s>|, ``x``; |
| | see |Back Extensible Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``pop_back<s>::type`` | A new ``string`` of following elements: |
| | [``begin<s>::type``, ``prior< end<s>::type >::type``); |
| | see |Back Extensible Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``push_front<s,x>::type`` | A new ``string`` of following elements: |
| | |begin/end<s>|, ``x``; see |Front Extensible Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``pop_front<s>::type`` | A new ``string`` of following elements: |
| | [``next< begin<s>::type >::type``, ``end<s>::type``); |
| | see |Front Extensible Sequence|. |
+---------------------------------------+-----------------------------------------------------------+
| ``c_str<s>::value`` | A null-terminated byte string such that |
| | ``c_str<s>::value[``\ *n*\ ``]`` is equal to the *n*\ -th |
| | character in ``s``, and |
| | ``c_str<s>::value[size<s>::type::value]`` is ``'\0'``. |
+---------------------------------------+-----------------------------------------------------------+
Example
-------
.. parsed-literal::
typedef mpl::string<'hell','o wo','rld'> hello;
typedef mpl::push_back<hello, mpl::char_<'!'> >::type hello2;
BOOST_ASSERT(0 == std::strcmp(mpl::c_str<hello2>::value, "hello world!"));
See also
--------
|Sequences|, |Variadic Sequence|, |Bidirectional Sequence|, |Extensible Sequence|, |Integral Sequence Wrapper|, |char_|, |c_str|

View File

@@ -0,0 +1,22 @@
#ifndef BOOST_MPL_CHAR_HPP_INCLUDED
#define BOOST_MPL_CHAR_HPP_INCLUDED
// Copyright Eric Niebler 2008
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/mpl for documentation.
// $Source$
// $Date: 2008-06-14 08:41:37 -0700 (Sat, 16 Jun 2008) $
// $Revision: 24874 $
#include <boost/mpl/char_fwd.hpp>
#define AUX_WRAPPER_VALUE_TYPE char
#include <boost/mpl/aux_/integral_wrapper.hpp>
#endif // BOOST_MPL_CHAR_HPP_INCLUDED

View File

@@ -0,0 +1,27 @@
#ifndef BOOST_MPL_CHAR_FWD_HPP_INCLUDED
#define BOOST_MPL_CHAR_FWD_HPP_INCLUDED
// Copyright Eric Niebler 2008
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/mpl for documentation.
// $Source$
// $Date: 2008-06-14 08:41:37 -0700 (Sat, 16 Jun 2008) $
// $Revision: 24874 $
#include <boost/mpl/aux_/adl_barrier.hpp>
#include <boost/mpl/aux_/nttp_decl.hpp>
BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_OPEN
template< BOOST_MPL_AUX_NTTP_DECL(char, N) > struct char_;
BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_CLOSE
BOOST_MPL_AUX_ADL_BARRIER_DECL(char_)
#endif // BOOST_MPL_CHAR_FWD_HPP_INCLUDED

View File

@@ -0,0 +1,21 @@
#ifndef BOOST_MPL_LIMITS_STRING_HPP_INCLUDED
#define BOOST_MPL_LIMITS_STRING_HPP_INCLUDED
// Copyright Eric Niebler 2009
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/mpl for documentation.
// $Id: string.hpp 49239 2009-04-01 09:10:26Z eric_niebler $
// $Date: 2009-04-01 02:10:26 -0700 (Wed, 1 Apr 2009) $
// $Revision: 49239 $
#if !defined(BOOST_MPL_LIMIT_STRING_SIZE)
# define BOOST_MPL_LIMIT_STRING_SIZE 32
#endif
#endif // BOOST_MPL_LIMITS_STRING_HPP_INCLUDED

View File

@@ -0,0 +1,555 @@
#ifndef BOOST_MPL_STRING_HPP_INCLUDED
#define BOOST_MPL_STRING_HPP_INCLUDED
// Copyright Eric Niebler 2009
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/mpl for documentation.
// $Id: string.hpp 49239 2009-04-01 09:10:26Z eric_niebler $
// $Date: 2009-04-01 02:10:26 -0700 (Wed, 1 Apr 2009) $
// $Revision: 49239 $
//
// Thanks to:
// Dmitry Goncharov for porting this to the Sun compiler
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/detail/endian.hpp>
#include <boost/mpl/limits/string.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/char.hpp>
#include <boost/mpl/copy.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/size_t.hpp>
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/joint_view.hpp>
#include <boost/mpl/insert_range.hpp>
#include <boost/mpl/back_inserter.hpp>
#include <boost/mpl/front_inserter.hpp>
#include <boost/mpl/iterator_range.hpp>
#include <boost/preprocessor/arithmetic/dec.hpp>
#include <boost/preprocessor/arithmetic/add.hpp>
#include <boost/preprocessor/arithmetic/div.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
namespace boost { namespace mpl
{
#define BOOST_MPL_STRING_MAX_PARAMS \
BOOST_PP_DIV(BOOST_PP_ADD(BOOST_MPL_LIMIT_STRING_SIZE, 3), 4)
// Low-level bit-twiddling is done by macros. Any implementation-defined behavior of
// multi-character literals should be localized to these macros.
#define BOOST_MPL_MULTICHAR_LENGTH(c) \
(std::size_t)((c>0xffffff)+(c>0xffff)+(c>0xff)+1)
#if defined(BOOST_LITTLE_ENDIAN) && defined(__SUNPRO_CC)
#define BOOST_MPL_MULTICHAR_AT(c,i) \
(char)(0xff&(c>>(8*(std::size_t)(i))))
#define BOOST_MPL_MULTICHAR_PUSH_BACK(c,i) \
((((unsigned char)(i))<<(BOOST_MPL_MULTICHAR_LENGTH(c)*8))|(c))
#define BOOST_MPL_MULTICHAR_PUSH_FRONT(c,i) \
(((c)<<8)|(unsigned char)(i))
#define BOOST_MPL_MULTICHAR_POP_BACK(c) \
(((1<<((BOOST_MPL_MULTICHAR_LENGTH(c)-1)*8))-1)&(c))
#define BOOST_MPL_MULTICHAR_POP_FRONT(c) \
((c)>>8)
#else
#define BOOST_MPL_MULTICHAR_AT(c,i) \
(char)(0xff&(c>>(8*(BOOST_MPL_MULTICHAR_LENGTH(c)-(std::size_t)(i)-1))))
#define BOOST_MPL_MULTICHAR_PUSH_BACK(c,i) \
(((c)<<8)|(unsigned char)(i))
#define BOOST_MPL_MULTICHAR_PUSH_FRONT(c,i) \
((((unsigned char)(i))<<(BOOST_MPL_MULTICHAR_LENGTH(c)*8))|(c))
#define BOOST_MPL_MULTICHAR_POP_BACK(c) \
((c)>>8)
#define BOOST_MPL_MULTICHAR_POP_FRONT(c) \
(((1<<((BOOST_MPL_MULTICHAR_LENGTH(c)-1)*8))-1)&(c))
#endif
struct string_tag;
struct string_iterator_tag;
template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_MPL_STRING_MAX_PARAMS, unsigned C, 0)>
struct string;
template<typename Sequence, unsigned I, unsigned J>
struct string_iterator;
template<typename Sequence>
struct sequence_tag;
template<typename Tag>
struct size_impl;
template<>
struct size_impl<mpl::string_tag>
{
template<typename Sequence>
struct apply;
#define M0(z, n, data) \
+ BOOST_MPL_MULTICHAR_LENGTH(BOOST_PP_CAT(C,n))
#define M1(z, n, data) \
template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned C)> \
struct apply<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)> > \
: mpl::size_t<(0 BOOST_PP_REPEAT_ ## z(n, M0, ~))> \
{};
BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_INC(BOOST_MPL_STRING_MAX_PARAMS), M1, ~)
#undef M0
#undef M1
};
template<>
struct size_impl<mpl::string_tag>::apply<mpl::string<> >
: mpl::size_t<0>
{};
template<typename Tag>
struct begin_impl;
template<>
struct begin_impl<mpl::string_tag>
{
template<typename Sequence>
struct apply
{
typedef mpl::string_iterator<Sequence, 0, 0> type;
};
};
template<typename Tag>
struct end_impl;
template<>
struct end_impl<mpl::string_tag>
{
template<typename Sequence>
struct apply;
#define M0(z,n,data) \
template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned C)> \
struct apply<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)> > \
{ \
typedef mpl::string_iterator<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)>, n, 0> type; \
};
BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_INC(BOOST_MPL_STRING_MAX_PARAMS), M0, ~)
#undef M0
};
template<>
struct end_impl<mpl::string_tag>::apply<mpl::string<> >
{
typedef mpl::string_iterator<mpl::string<>, 0, 0> type;
};
template<typename Tag>
struct push_back_impl;
template<>
struct push_back_impl<mpl::string_tag>
{
template<typename Sequence, typename Value, bool B = (4==BOOST_MPL_MULTICHAR_LENGTH(Sequence::back_))>
struct apply
{
BOOST_MPL_ASSERT_MSG(
(BOOST_MPL_LIMIT_STRING_SIZE != mpl::size<Sequence>::type::value)
, PUSH_BACK_FAILED_MPL_STRING_IS_FULL
, (Sequence)
);
// If the above assertion didn't fire, then the string is sparse.
// Repack the string and retry the push_back
typedef
typename mpl::push_back<
typename mpl::copy<
Sequence
, mpl::back_inserter<mpl::string<> >
>::type
, Value
>::type
type;
};
template<typename Value>
struct apply<mpl::string<>, Value, false>
{
typedef mpl::string<(char)Value::value> type;
};
#define M0(z,n,data) \
template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned C), typename Value> \
struct apply<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)>, Value, false> \
{ \
typedef \
mpl::string< \
BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), C) \
BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
(BOOST_PP_CAT(C,BOOST_PP_DEC(n))>0xffffff) \
?BOOST_PP_CAT(C,BOOST_PP_DEC(n)) \
:BOOST_MPL_MULTICHAR_PUSH_BACK(BOOST_PP_CAT(C,BOOST_PP_DEC(n)), Value::value) \
, (BOOST_PP_CAT(C,BOOST_PP_DEC(n))>0xffffff) \
?(char)Value::value \
:0 \
> \
type; \
};
BOOST_PP_REPEAT_FROM_TO(1, BOOST_MPL_STRING_MAX_PARAMS, M0, ~)
#undef M0
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C), typename Value>
struct apply<mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>, Value, false>
{
typedef
mpl::string<
BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS), C)
, BOOST_MPL_MULTICHAR_PUSH_BACK(BOOST_PP_CAT(C,BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS)), Value::value)
>
type;
};
};
template<typename Tag>
struct pop_back_impl;
template<>
struct pop_back_impl<mpl::string_tag>
{
template<typename Sequence>
struct apply;
#define M0(z,n,data) \
template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned C)> \
struct apply<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)> > \
{ \
BOOST_MPL_ASSERT_MSG((C0 != 0), POP_BACK_FAILED_MPL_STRING_IS_EMPTY, (mpl::string<>)); \
typedef \
mpl::string< \
BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), C) \
BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
BOOST_MPL_MULTICHAR_POP_BACK(BOOST_PP_CAT(C,BOOST_PP_DEC(n))) \
> \
type; \
};
BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_INC(BOOST_MPL_STRING_MAX_PARAMS), M0, ~)
#undef M0
};
template<typename Tag>
struct push_front_impl;
template<>
struct push_front_impl<mpl::string_tag>
{
template<typename Sequence, typename Value, bool B = (4==BOOST_MPL_MULTICHAR_LENGTH(Sequence::front_))>
struct apply
{
BOOST_MPL_ASSERT_MSG(
(BOOST_MPL_LIMIT_STRING_SIZE != mpl::size<Sequence>::type::value)
, PUSH_FRONT_FAILED_MPL_STRING_IS_FULL
, (Sequence)
);
// If the above assertion didn't fire, then the string is sparse.
// Repack the string and retry the push_front.
typedef
typename mpl::push_front<
typename mpl::reverse_copy<
Sequence
, mpl::front_inserter<string<> >
>::type
, Value
>::type
type;
};
#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
template<typename Value>
struct apply<mpl::string<>, Value, false>
{
typedef mpl::string<(char)Value::value> type;
};
#endif
#define M0(z,n,data) \
template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned C), typename Value> \
struct apply<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)>, Value, true> \
{ \
typedef \
mpl::string< \
(char)Value::value \
BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, C) \
> \
type; \
};
BOOST_PP_REPEAT_FROM_TO(1, BOOST_MPL_STRING_MAX_PARAMS, M0, ~)
#undef M0
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C), typename Value>
struct apply<mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>, Value, false>
{
typedef
mpl::string<
BOOST_MPL_MULTICHAR_PUSH_FRONT(C0, Value::value)
, BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)
>
type0;
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
typedef
typename mpl::if_<
mpl::empty<mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)> >
, mpl::string<(char)Value::value>
, type0
>::type
type;
#else
typedef type0 type;
#endif
};
};
template<typename Tag>
struct pop_front_impl;
template<>
struct pop_front_impl<mpl::string_tag>
{
template<typename Sequence, bool B = (1==BOOST_MPL_MULTICHAR_LENGTH(Sequence::front_))>
struct apply;
#define M0(z,n,data) \
template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned C)> \
struct apply<mpl::string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)>, true> \
{ \
BOOST_MPL_ASSERT_MSG((C0 != 0), POP_FRONT_FAILED_MPL_STRING_IS_EMPTY, (mpl::string<>)); \
typedef \
mpl::string<BOOST_PP_ENUM_SHIFTED_PARAMS_Z(z, n, C)> \
type; \
};
BOOST_PP_REPEAT_FROM_TO(1, BOOST_MPL_STRING_MAX_PARAMS, M0, ~)
#undef M0
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C)>
struct apply<mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>, false>
{
typedef
mpl::string<
BOOST_MPL_MULTICHAR_POP_FRONT(C0)
, BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)
>
type;
};
};
template<typename Tag>
struct insert_range_impl;
template<>
struct insert_range_impl<mpl::string_tag>
{
template<typename Sequence, typename Pos, typename Range>
struct apply
: mpl::copy<
mpl::joint_view<
mpl::iterator_range<
mpl::string_iterator<Sequence, 0, 0>
, Pos
>
, mpl::joint_view<
Range
, mpl::iterator_range<
Pos
, typename mpl::end<Sequence>::type
>
>
>
, mpl::back_inserter<mpl::string<> >
>
{};
};
template<typename Tag>
struct insert_impl;
template<>
struct insert_impl<mpl::string_tag>
{
template<typename Sequence, typename Pos, typename Value>
struct apply
: mpl::insert_range<Sequence, Pos, mpl::string<(char)Value::value> >
{};
};
template<typename Tag>
struct erase_impl;
template<>
struct erase_impl<mpl::string_tag>
{
template<typename Sequence, typename First, typename Last>
struct apply
: mpl::copy<
mpl::joint_view<
mpl::iterator_range<
mpl::string_iterator<Sequence, 0, 0>
, First
>
, mpl::iterator_range<
typename mpl::if_na<Last, typename mpl::next<First>::type>::type
, typename mpl::end<Sequence>::type
>
>
, mpl::back_inserter<mpl::string<> >
>
{};
};
template<typename Tag>
struct clear_impl;
template<>
struct clear_impl<mpl::string_tag>
{
template<typename>
struct apply
{
typedef mpl::string<> type;
};
};
#define M0(z, n, data) \
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C), unsigned J> \
struct string_iterator<mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>, n, J> \
{ \
enum { eomc_ = (BOOST_MPL_MULTICHAR_LENGTH(BOOST_PP_CAT(C, n)) == J + 1) }; \
typedef mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)> string; \
typedef std::bidirectional_iterator_tag category; \
typedef \
mpl::string_iterator<string, n + eomc_, eomc_ ? 0 : J + 1> \
next; \
typedef \
mpl::string_iterator<string, n, J - 1> \
prior; \
typedef mpl::char_<BOOST_MPL_MULTICHAR_AT(BOOST_PP_CAT(C, n), J)> type; \
}; \
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C)> \
struct string_iterator<mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>, n, 0> \
{ \
enum { eomc_ = (BOOST_MPL_MULTICHAR_LENGTH(BOOST_PP_CAT(C, n)) == 1) }; \
typedef mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)> string; \
typedef std::bidirectional_iterator_tag category; \
typedef \
mpl::string_iterator<string, n + eomc_, !eomc_> \
next; \
typedef \
mpl::string_iterator< \
string \
, n - 1 \
, BOOST_MPL_MULTICHAR_LENGTH(BOOST_PP_CAT(C, BOOST_PP_DEC(n))) - 1 \
> \
prior; \
typedef mpl::char_<BOOST_MPL_MULTICHAR_AT(BOOST_PP_CAT(C, n), 0)> type; \
};
BOOST_PP_REPEAT(BOOST_MPL_STRING_MAX_PARAMS, M0, ~)
#undef M0
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C)>
struct string
{
/// INTERNAL ONLY
enum
{
front_ = C0
, back_ = BOOST_PP_CAT(C, BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS))
};
typedef string type;
typedef string_tag tag;
};
namespace aux_
{
template<typename It, typename End>
struct next_unless
: mpl::next<It>
{};
template<typename End>
struct next_unless<End, End>
{
typedef End type;
};
template<typename It, typename End>
struct deref_unless
: mpl::deref<It>
{};
template<typename End>
struct deref_unless<End, End>
{
typedef mpl::char_<'\0'> type;
};
}
template<typename Sequence>
struct c_str
{
typedef typename mpl::end<Sequence>::type iend;
typedef typename mpl::begin<Sequence>::type i0;
#define M0(z, n, data) \
typedef \
typename mpl::aux_::next_unless<BOOST_PP_CAT(i, n), iend>::type \
BOOST_PP_CAT(i, BOOST_PP_INC(n));
BOOST_PP_REPEAT(BOOST_MPL_LIMIT_STRING_SIZE, M0, ~)
#undef M0
typedef c_str type;
static char const value[];
};
template<typename Sequence>
char const c_str<Sequence>::value[] =
{
#define M0(z, n, data) \
mpl::aux_::deref_unless<BOOST_PP_CAT(i, n), iend>::type::value,
BOOST_PP_REPEAT(BOOST_MPL_LIMIT_STRING_SIZE, M0, ~)
#undef M0
'\0'
};
}} // namespace boost
#endif // BOOST_MPL_STRING_HPP_INCLUDED

View File

@@ -44,6 +44,7 @@ compile inherit.cpp ;
compile insert.cpp ; compile insert.cpp ;
compile insert_range.cpp ; compile insert_range.cpp ;
run int.cpp ; run int.cpp ;
run char.cpp ;
run integral_c.cpp : : : <toolset>vacpp:<cxxflags>-qchars=signed ; run integral_c.cpp : : : <toolset>vacpp:<cxxflags>-qchars=signed ;
compile is_placeholder.cpp ; compile is_placeholder.cpp ;
compile is_sequence.cpp ; compile is_sequence.cpp ;
@@ -90,3 +91,4 @@ compile upper_bound.cpp ;
compile vector.cpp ; compile vector.cpp ;
compile vector_c.cpp ; compile vector_c.cpp ;
compile zip_view.cpp ; compile zip_view.cpp ;
run string.cpp ;

24
test/char.cpp Normal file
View File

@@ -0,0 +1,24 @@
// Copyright Eric Niebler 2008
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/mpl for documentation.
// $Id: char.cpp 49240 2009-04-01 09:21:07Z eric_niebler $
// $Date: 2009-04-01 02:21:07 -0700 (Wed, 1 Apr 2009) $
// $Revision: 49240 $
#include <boost/mpl/char.hpp>
#include <boost/preprocessor/repeat.hpp>
#include "integral_wrapper_test.hpp"
MPL_TEST_CASE()
{
# define WRAPPER(T, i) char_<i>
BOOST_PP_REPEAT(10, INTEGRAL_WRAPPER_TEST, char)
}

475
test/string.cpp Normal file
View File

@@ -0,0 +1,475 @@
// Copyright Eric Niebler 2009
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/mpl for documentation.
// $Id: string.cpp 49240 2009-04-01 09:21:07Z eric_niebler $
// $Date: 2009-04-01 02:21:07 -0700 (Wed, 1 Apr 2009) $
// $Revision: 49240 $
#include <string>
#include <cstring>
#include <iostream>
#include <boost/mpl/string.hpp>
#include <boost/mpl/back.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/erase.hpp>
#include <boost/mpl/insert.hpp>
#include <boost/mpl/advance.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/pop_back.hpp>
#include <boost/mpl/pop_front.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/push_front.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/detail/lightweight_test.hpp>
namespace mpl = boost::mpl;
// Accept a string as a template parameter!
template<char const *sz>
struct greeting
{
std::string say_hello() const
{
return sz;
}
};
struct push_char
{
push_char(std::string &str)
: str_(&str)
{}
void operator()(char ch) const
{
this->str_->push_back(ch);
}
std::string *str_;
};
int main()
{
// Test mpl::size of strings
{
typedef mpl::string<'aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaa'> almost_full;
typedef mpl::string<'aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa'> full;
BOOST_MPL_ASSERT_RELATION(0, ==, (mpl::size<mpl::string<> >::value));
BOOST_MPL_ASSERT_RELATION(1, ==, (mpl::size<mpl::string<'a'> >::value));
BOOST_MPL_ASSERT_RELATION(2, ==, (mpl::size<mpl::string<'ab'> >::value));
BOOST_MPL_ASSERT_RELATION(2, ==, (mpl::size<mpl::string<'a','b'> >::value));
BOOST_MPL_ASSERT_RELATION(4, ==, (mpl::size<mpl::string<'abcd'> >::value));
BOOST_MPL_ASSERT_RELATION(5, ==, (mpl::size<mpl::string<'abcd','e'> >::value));
BOOST_MPL_ASSERT_RELATION(31, ==, (mpl::size<almost_full>::value));
BOOST_MPL_ASSERT_RELATION(32, ==, (mpl::size<full>::value));
}
// Test mpl::begin and mpl::end with strings
{
typedef mpl::string<'aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaa'> almost_full;
typedef mpl::string<'aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa'> full;
BOOST_MPL_ASSERT((
boost::is_same<
mpl::begin<mpl::string<> >::type
, mpl::end<mpl::string<> >::type
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::begin<mpl::string<'a'> >::type
, mpl::string_iterator<mpl::string<'a'>, 0, 0>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::end<mpl::string<'a'> >::type
, mpl::string_iterator<mpl::string<'a'>, 1, 0>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::begin<almost_full>::type
, mpl::string_iterator<almost_full, 0, 0>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::end<almost_full>::type
, mpl::string_iterator<almost_full, 8, 0>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::begin<full>::type
, mpl::string_iterator<full, 0, 0>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::end<full>::type
, mpl::string_iterator<full, 8, 0>
>
));
}
// testing push_back
{
typedef mpl::push_back<mpl::string<>, mpl::char_<'a'> >::type t1;
BOOST_MPL_ASSERT((boost::is_same<t1, mpl::string<'a'> >));
typedef mpl::push_back<t1, mpl::char_<'b'> >::type t2;
BOOST_MPL_ASSERT((boost::is_same<t2, mpl::string<'ab'> >));
typedef mpl::push_back<t2, mpl::char_<'c'> >::type t3;
BOOST_MPL_ASSERT((boost::is_same<t3, mpl::string<'abc'> >));
typedef mpl::push_back<t3, mpl::char_<'d'> >::type t4;
BOOST_MPL_ASSERT((boost::is_same<t4, mpl::string<'abcd'> >));
typedef mpl::push_back<t4, mpl::char_<'e'> >::type t5;
BOOST_MPL_ASSERT((boost::is_same<t5, mpl::string<'abcd','e'> >));
typedef mpl::string<'aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaa'> almost_full;
typedef mpl::push_back<almost_full, mpl::char_<'X'> >::type t6;
BOOST_MPL_ASSERT((boost::is_same<t6, mpl::string<'aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaX'> >));
}
// Test mpl::next
{
typedef mpl::string<'a','bc','def','ghij'> s;
typedef mpl::begin<s>::type i0;
BOOST_MPL_ASSERT((boost::is_same<i0, mpl::string_iterator<s,0,0> >));
typedef mpl::next<i0>::type i1;
BOOST_MPL_ASSERT((boost::is_same<i1, mpl::string_iterator<s,1,0> >));
typedef mpl::next<i1>::type i2;
BOOST_MPL_ASSERT((boost::is_same<i2, mpl::string_iterator<s,1,1> >));
typedef mpl::next<i2>::type i3;
BOOST_MPL_ASSERT((boost::is_same<i3, mpl::string_iterator<s,2,0> >));
typedef mpl::next<i3>::type i4;
BOOST_MPL_ASSERT((boost::is_same<i4, mpl::string_iterator<s,2,1> >));
typedef mpl::next<i4>::type i5;
BOOST_MPL_ASSERT((boost::is_same<i5, mpl::string_iterator<s,2,2> >));
typedef mpl::next<i5>::type i6;
BOOST_MPL_ASSERT((boost::is_same<i6, mpl::string_iterator<s,3,0> >));
typedef mpl::next<i6>::type i7;
BOOST_MPL_ASSERT((boost::is_same<i7, mpl::string_iterator<s,3,1> >));
typedef mpl::next<i7>::type i8;
BOOST_MPL_ASSERT((boost::is_same<i8, mpl::string_iterator<s,3,2> >));
typedef mpl::next<i8>::type i9;
BOOST_MPL_ASSERT((boost::is_same<i9, mpl::string_iterator<s,3,3> >));
typedef mpl::next<i9>::type i10;
BOOST_MPL_ASSERT((boost::is_same<i10, mpl::string_iterator<s,4,0> >));
BOOST_MPL_ASSERT((boost::is_same<i10, mpl::end<s>::type>));
}
// Test mpl::prior
{
typedef mpl::string<'a','bc','def','ghij'> s;
typedef mpl::end<s>::type i10;
BOOST_MPL_ASSERT((boost::is_same<i10, mpl::string_iterator<s,4,0> >));
typedef mpl::prior<i10>::type i9;
BOOST_MPL_ASSERT((boost::is_same<i9, mpl::string_iterator<s,3,3> >));
typedef mpl::prior<i9>::type i8;
BOOST_MPL_ASSERT((boost::is_same<i8, mpl::string_iterator<s,3,2> >));
typedef mpl::prior<i8>::type i7;
BOOST_MPL_ASSERT((boost::is_same<i7, mpl::string_iterator<s,3,1> >));
typedef mpl::prior<i7>::type i6;
BOOST_MPL_ASSERT((boost::is_same<i6, mpl::string_iterator<s,3,0> >));
typedef mpl::prior<i6>::type i5;
BOOST_MPL_ASSERT((boost::is_same<i5, mpl::string_iterator<s,2,2> >));
typedef mpl::prior<i5>::type i4;
BOOST_MPL_ASSERT((boost::is_same<i4, mpl::string_iterator<s,2,1> >));
typedef mpl::prior<i4>::type i3;
BOOST_MPL_ASSERT((boost::is_same<i3, mpl::string_iterator<s,2,0> >));
typedef mpl::prior<i3>::type i2;
BOOST_MPL_ASSERT((boost::is_same<i2, mpl::string_iterator<s,1,1> >));
typedef mpl::prior<i2>::type i1;
BOOST_MPL_ASSERT((boost::is_same<i1, mpl::string_iterator<s,1,0> >));
typedef mpl::prior<i1>::type i0;
BOOST_MPL_ASSERT((boost::is_same<i0, mpl::string_iterator<s,0,0> >));
BOOST_MPL_ASSERT((boost::is_same<i0, mpl::begin<s>::type>));
}
// Test mpl::deref
{
typedef mpl::string<'a','bc','def','ghij'> s;
typedef mpl::begin<s>::type i0;
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<i0>::type, mpl::char_<'a'> >));
typedef mpl::next<i0>::type i1;
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<i1>::type, mpl::char_<'b'> >));
typedef mpl::next<i1>::type i2;
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<i2>::type, mpl::char_<'c'> >));
typedef mpl::next<i2>::type i3;
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<i3>::type, mpl::char_<'d'> >));
typedef mpl::next<i3>::type i4;
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<i4>::type, mpl::char_<'e'> >));
typedef mpl::next<i4>::type i5;
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<i5>::type, mpl::char_<'f'> >));
typedef mpl::next<i5>::type i6;
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<i6>::type, mpl::char_<'g'> >));
typedef mpl::next<i6>::type i7;
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<i7>::type, mpl::char_<'h'> >));
typedef mpl::next<i7>::type i8;
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<i8>::type, mpl::char_<'i'> >));
typedef mpl::next<i8>::type i9;
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<i9>::type, mpl::char_<'j'> >));
}
// testing push_back
{
typedef mpl::push_back<mpl::string<>, mpl::char_<'a'> >::type t1;
BOOST_MPL_ASSERT((boost::is_same<t1, mpl::string<'a'> >));
typedef mpl::push_back<t1, mpl::char_<'b'> >::type t2;
BOOST_MPL_ASSERT((boost::is_same<t2, mpl::string<'ab'> >));
typedef mpl::push_back<t2, mpl::char_<'c'> >::type t3;
BOOST_MPL_ASSERT((boost::is_same<t3, mpl::string<'abc'> >));
typedef mpl::push_back<t3, mpl::char_<'d'> >::type t4;
BOOST_MPL_ASSERT((boost::is_same<t4, mpl::string<'abcd'> >));
typedef mpl::push_back<t4, mpl::char_<'e'> >::type t5;
BOOST_MPL_ASSERT((boost::is_same<t5, mpl::string<'abcd','e'> >));
typedef mpl::string<'aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaa'> almost_full;
typedef mpl::push_back<almost_full, mpl::char_<'X'> >::type t6;
BOOST_MPL_ASSERT((boost::is_same<t6, mpl::string<'aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaX'> >));
typedef mpl::string<'a','a','a','a','a','a','a','aaaa'> must_repack;
typedef mpl::push_back<must_repack, mpl::char_<'X'> >::type t7;
BOOST_MPL_ASSERT((boost::is_same<t7, mpl::string<'aaaa','aaaa','aaaX'> >));
}
BOOST_MPL_ASSERT((mpl::empty<mpl::string<> >));
BOOST_MPL_ASSERT_NOT((mpl::empty<mpl::string<'hi!'> >));
// testing push_front
{
typedef mpl::push_front<mpl::string<>, mpl::char_<'a'> >::type t1;
BOOST_MPL_ASSERT((boost::is_same<t1, mpl::string<'a'> >));
typedef mpl::push_front<t1, mpl::char_<'b'> >::type t2;
BOOST_MPL_ASSERT((boost::is_same<t2, mpl::string<'ba'> >));
typedef mpl::push_front<t2, mpl::char_<'c'> >::type t3;
BOOST_MPL_ASSERT((boost::is_same<t3, mpl::string<'cba'> >));
typedef mpl::push_front<t3, mpl::char_<'d'> >::type t4;
BOOST_MPL_ASSERT((boost::is_same<t4, mpl::string<'dcba'> >));
typedef mpl::push_front<t4, mpl::char_<'e'> >::type t5;
BOOST_MPL_ASSERT((boost::is_same<t5, mpl::string<'e','dcba'> >));
typedef mpl::string<'aaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa'> almost_full;
typedef mpl::push_front<almost_full, mpl::char_<'X'> >::type t6;
BOOST_MPL_ASSERT((boost::is_same<t6, mpl::string<'Xaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa'> >));
typedef mpl::string<'aaaa','a','a','a','a','a','a','a'> must_repack;
typedef mpl::push_front<must_repack, mpl::char_<'X'> >::type t7;
BOOST_MPL_ASSERT((boost::is_same<t7, mpl::string<'Xaaa','aaaa','aaaa'> >));
}
// Test c_str<>
BOOST_TEST(0 == std::strcmp(
mpl::c_str<mpl::string<> >::value
, ""
));
BOOST_TEST(0 == std::strcmp(
mpl::c_str<mpl::string<'Hell','o wo','rld!'> >::value
, "Hell" "o wo" "rld!"
));
BOOST_TEST(0 == std::strcmp(
mpl::c_str<mpl::string<'aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaX'> >::value
, "aaaa" "aaaa" "aaaa" "aaaa" "aaaa" "aaaa" "aaaa" "aaaX"
));
// test using a string as a template parameter
greeting<mpl::c_str<mpl::string<'Hell','o wo','rld!'> >::value> g;
BOOST_TEST("Hello world!" == g.say_hello());
std::string result;
mpl::for_each<mpl::string<'Hell','o wo','rld!'> >(push_char(result));
BOOST_TEST("Hello world!" == result);
BOOST_TEST(('h' == mpl::front<mpl::string<'hi!'> >::type()));
BOOST_TEST(('!' == mpl::back<mpl::string<'hi!'> >::type()));
// back-inserter with copy
typedef mpl::vector_c<char, 'a','b','c','d','e'> rgc;
BOOST_TEST(0 == std::strcmp("abcde", mpl::c_str<rgc>::value));
typedef mpl::copy<rgc, mpl::back_inserter<mpl::string<> > >::type str;
BOOST_TEST(0 == std::strcmp("abcde", mpl::c_str<str>::value));
// test insert_range and erase
{
typedef mpl::string<'Hell','o wo','rld!'> hello;
typedef mpl::advance_c<mpl::begin<hello>::type, 5>::type where;
typedef mpl::string<' cru','el'> cruel;
typedef mpl::insert_range<hello, where, cruel>::type hello_cruel;
BOOST_TEST(0 == std::strcmp("Hello cruel world!", mpl::c_str<hello_cruel>::value));
typedef mpl::erase<hello, mpl::begin<hello>::type, where>::type erased1;
BOOST_TEST(0 == std::strcmp(" world!", mpl::c_str<erased1>::value));
}
// test pop_front
{
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_front<mpl::string<'a'> >::type
, mpl::string<>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_front<mpl::string<'ab'> >::type
, mpl::string<'b'>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_front<mpl::string<'abc'> >::type
, mpl::string<'bc'>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_front<mpl::string<'abcd'> >::type
, mpl::string<'bcd'>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_front<mpl::string<'abcd','e'> >::type
, mpl::string<'bcd','e'>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_front<mpl::string<'d','e'> >::type
, mpl::string<'e'>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_front<mpl::string<'aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa'> >::type
, mpl::string<'aaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa'>
>
));
}
// test pop_back
{
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_back<mpl::string<'a'> >::type
, mpl::string<>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_back<mpl::string<'ab'> >::type
, mpl::string<'a'>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_back<mpl::string<'abc'> >::type
, mpl::string<'ab'>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_back<mpl::string<'abcd'> >::type
, mpl::string<'abc'>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_back<mpl::string<'abcd','e'> >::type
, mpl::string<'abcd'>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_back<mpl::string<'d','e'> >::type
, mpl::string<'d'>
>
));
BOOST_MPL_ASSERT((
boost::is_same<
mpl::pop_back<mpl::string<'aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa'> >::type
, mpl::string<'aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaaa','aaa'>
>
));
}
return boost::report_errors();
}