forked from boostorg/mpl
mpl::string is a bidirectional sequence, not random access; c_str is a separate metafunction, not a class static
[SVN r52314]
This commit is contained in:
+297
-215
@@ -4,8 +4,8 @@
|
||||
|
||||
// Copyright Eric Niebler 2009
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// 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.
|
||||
@@ -14,23 +14,21 @@
|
||||
// $Date: 2009-04-01 02:10:26 -0700 (Wed, 1 Apr 2009) $
|
||||
// $Revision: 49239 $
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/mpl/char.hpp>
|
||||
#include <boost/mpl/long.hpp>
|
||||
#include <boost/mpl/back.hpp>
|
||||
#include <boost/mpl/copy.hpp>
|
||||
#include <boost/mpl/size.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/size_t.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/repetition/enum.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>
|
||||
@@ -42,7 +40,7 @@ namespace boost { namespace mpl
|
||||
#ifndef BOOST_MPL_STRING_MAX_LENGTH
|
||||
# define BOOST_MPL_STRING_MAX_LENGTH 32
|
||||
#endif
|
||||
|
||||
|
||||
#define BOOST_MPL_STRING_MAX_PARAMS BOOST_PP_DIV(BOOST_PP_ADD(BOOST_MPL_STRING_MAX_LENGTH, 3), 4)
|
||||
|
||||
#define BOOST_MPL_MULTICHAR_LENGTH(c) (std::size_t)((c>0xffffff)+(c>0xffff)+(c>0xff)+1)
|
||||
@@ -51,10 +49,10 @@ namespace boost { namespace mpl
|
||||
struct string_tag;
|
||||
struct string_iterator_tag;
|
||||
|
||||
template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_MPL_STRING_MAX_PARAMS, unsigned int C, 0)>
|
||||
template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_MPL_STRING_MAX_PARAMS, unsigned C, 0)>
|
||||
struct string;
|
||||
|
||||
template<typename Sequence, unsigned long N>
|
||||
template<typename Sequence, unsigned I, unsigned J>
|
||||
struct string_iterator;
|
||||
|
||||
template<typename Sequence>
|
||||
@@ -64,36 +62,40 @@ namespace boost { namespace mpl
|
||||
struct size_impl;
|
||||
|
||||
template<>
|
||||
struct size_impl<string_tag>
|
||||
struct size_impl<mpl::string_tag>
|
||||
{
|
||||
template<typename Sequence>
|
||||
struct apply
|
||||
: mpl::size_t<Sequence::size>
|
||||
{};
|
||||
};
|
||||
struct apply;
|
||||
|
||||
template<typename Tag>
|
||||
struct at_impl;
|
||||
#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 at_impl<string_tag>
|
||||
{
|
||||
template<typename Sequence, typename N>
|
||||
struct apply
|
||||
: Sequence::template at<N::value>
|
||||
{};
|
||||
};
|
||||
struct size_impl<mpl::string_tag>::apply<mpl::string<> >
|
||||
: mpl::size_t<0>
|
||||
{};
|
||||
|
||||
template<typename Tag>
|
||||
struct begin_impl;
|
||||
|
||||
template<>
|
||||
struct begin_impl<string_tag>
|
||||
struct begin_impl<mpl::string_tag>
|
||||
{
|
||||
template<typename Sequence>
|
||||
struct apply
|
||||
{
|
||||
typedef string_iterator<Sequence, 0> type;
|
||||
typedef mpl::string_iterator<Sequence, 0, 0> type;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -101,102 +103,212 @@ namespace boost { namespace mpl
|
||||
struct end_impl;
|
||||
|
||||
template<>
|
||||
struct end_impl<string_tag>
|
||||
struct end_impl<mpl::string_tag>
|
||||
{
|
||||
template<typename Sequence>
|
||||
struct apply
|
||||
{
|
||||
typedef string_iterator<Sequence, Sequence::size> type;
|
||||
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<string_tag>
|
||||
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(false, PUSH_BACK_FAILED_MPL_STRING_IS_FULL, (Sequence));
|
||||
typedef void type;
|
||||
BOOST_MPL_ASSERT_MSG(
|
||||
(BOOST_MPL_STRING_MAX_LENGTH != 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<string<>, Value, false>
|
||||
struct apply<mpl::string<>, Value, false>
|
||||
{
|
||||
typedef string<(char)Value::value> type;
|
||||
typedef mpl::string<(char)Value::value> type;
|
||||
};
|
||||
|
||||
#define M0(z,n,data) \
|
||||
template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned int C), typename Value> \
|
||||
struct apply<string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)>, Value, false> \
|
||||
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 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_PP_CAT(C,BOOST_PP_DEC(n))<<8)|(unsigned char)Value::value \
|
||||
, (BOOST_PP_CAT(C,BOOST_PP_DEC(n))>0xffffff) \
|
||||
?(char)Value::value \
|
||||
:0 \
|
||||
> type; \
|
||||
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_PP_CAT(C,BOOST_PP_DEC(n))<<8)|(unsigned char)Value::value \
|
||||
, (BOOST_PP_CAT(C,BOOST_PP_DEC(n))>0xffffff) \
|
||||
?(char)Value::value \
|
||||
:0 \
|
||||
> \
|
||||
type; \
|
||||
};
|
||||
|
||||
BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS), M0, ~)
|
||||
#undef M0
|
||||
|
||||
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned int C), typename Value>
|
||||
struct apply<string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>, Value, false>
|
||||
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 string<
|
||||
BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS), C)
|
||||
, (BOOST_PP_CAT(C,BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS))<<8)|(unsigned char)Value::value
|
||||
> type;
|
||||
typedef
|
||||
mpl::string<
|
||||
BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS), C)
|
||||
, (BOOST_PP_CAT(C,BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS))<<8)|(unsigned char)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_PP_CAT(C,BOOST_PP_DEC(n))>>8) \
|
||||
> \
|
||||
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<string_tag>
|
||||
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(false, PUSH_FRONT_FAILED_MPL_STRING_IS_FULL, (Sequence));
|
||||
typedef void type;
|
||||
BOOST_MPL_ASSERT_MSG(
|
||||
(BOOST_MPL_STRING_MAX_LENGTH != 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;
|
||||
};
|
||||
|
||||
template<typename Value>
|
||||
struct apply<string<>, Value, false>
|
||||
struct apply<mpl::string<>, Value, false>
|
||||
{
|
||||
typedef string<(char)Value::value> type;
|
||||
typedef mpl::string<(char)Value::value> type;
|
||||
};
|
||||
|
||||
#define M0(z,n,data) \
|
||||
template<BOOST_PP_ENUM_PARAMS_Z(z, n, unsigned int C), typename Value> \
|
||||
struct apply<string<BOOST_PP_ENUM_PARAMS_Z(z, n, C)>, Value, true> \
|
||||
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 string< \
|
||||
(char)Value::value \
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, C) \
|
||||
> type; \
|
||||
typedef \
|
||||
mpl::string< \
|
||||
(char)Value::value \
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, C) \
|
||||
> \
|
||||
type; \
|
||||
};
|
||||
|
||||
BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS), M0, ~)
|
||||
#undef M0
|
||||
|
||||
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned int C), typename Value>
|
||||
struct apply<string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>, Value, false>
|
||||
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 string<
|
||||
((((unsigned char)Value::value)<<(BOOST_MPL_MULTICHAR_LENGTH(C0)*8))|C0)
|
||||
, BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)
|
||||
> type;
|
||||
typedef
|
||||
mpl::string<
|
||||
((((unsigned char)Value::value)<<(BOOST_MPL_MULTICHAR_LENGTH(C0)*8))|C0)
|
||||
, BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)
|
||||
>
|
||||
type;
|
||||
};
|
||||
};
|
||||
|
||||
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_PP_DEC(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<
|
||||
(((1<<((BOOST_MPL_MULTICHAR_LENGTH(C0)-1)*8))-1)&C0)
|
||||
, BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)
|
||||
>
|
||||
type;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -204,25 +316,25 @@ namespace boost { namespace mpl
|
||||
struct insert_range_impl;
|
||||
|
||||
template<>
|
||||
struct insert_range_impl<string_tag>
|
||||
struct insert_range_impl<mpl::string_tag>
|
||||
{
|
||||
template<typename Sequence, typename Pos, typename Range>
|
||||
struct apply
|
||||
: copy<
|
||||
joint_view<
|
||||
iterator_range<
|
||||
string_iterator<Sequence, 0>
|
||||
: mpl::copy<
|
||||
mpl::joint_view<
|
||||
mpl::iterator_range<
|
||||
mpl::string_iterator<Sequence, 0, 0>
|
||||
, Pos
|
||||
>
|
||||
, joint_view<
|
||||
, mpl::joint_view<
|
||||
Range
|
||||
, iterator_range<
|
||||
, mpl::iterator_range<
|
||||
Pos
|
||||
, string_iterator<Sequence, Sequence::size>
|
||||
, typename mpl::end<Sequence>::type
|
||||
>
|
||||
>
|
||||
>
|
||||
, back_inserter<string<> >
|
||||
, mpl::back_inserter<mpl::string<> >
|
||||
>
|
||||
{};
|
||||
};
|
||||
@@ -231,11 +343,11 @@ namespace boost { namespace mpl
|
||||
struct insert_impl;
|
||||
|
||||
template<>
|
||||
struct insert_impl<string_tag>
|
||||
struct insert_impl<mpl::string_tag>
|
||||
{
|
||||
template<typename Sequence, typename Pos, typename Value>
|
||||
struct apply
|
||||
: insert_range<Sequence, Pos, string<(char)Value::value> >
|
||||
: mpl::insert_range<Sequence, Pos, mpl::string<(char)Value::value> >
|
||||
{};
|
||||
};
|
||||
|
||||
@@ -243,22 +355,22 @@ namespace boost { namespace mpl
|
||||
struct erase_impl;
|
||||
|
||||
template<>
|
||||
struct erase_impl<string_tag>
|
||||
struct erase_impl<mpl::string_tag>
|
||||
{
|
||||
template<typename Sequence, typename First, typename Last>
|
||||
struct apply
|
||||
: copy<
|
||||
joint_view<
|
||||
iterator_range<
|
||||
string_iterator<Sequence, 0>
|
||||
: mpl::copy<
|
||||
mpl::joint_view<
|
||||
mpl::iterator_range<
|
||||
mpl::string_iterator<Sequence, 0, 0>
|
||||
, First
|
||||
>
|
||||
, iterator_range<
|
||||
typename if_na<Last, typename next<First>::type>::type
|
||||
, string_iterator<Sequence, Sequence::size>
|
||||
, mpl::iterator_range<
|
||||
typename mpl::if_na<Last, typename mpl::next<First>::type>::type
|
||||
, typename mpl::end<Sequence>::type
|
||||
>
|
||||
>
|
||||
, back_inserter<string<> >
|
||||
, mpl::back_inserter<mpl::string<> >
|
||||
>
|
||||
{};
|
||||
};
|
||||
@@ -267,152 +379,122 @@ namespace boost { namespace mpl
|
||||
struct clear_impl;
|
||||
|
||||
template<>
|
||||
struct clear_impl<string_tag>
|
||||
struct clear_impl<mpl::string_tag>
|
||||
{
|
||||
template<typename>
|
||||
struct apply
|
||||
{
|
||||
typedef string<> type;
|
||||
typedef mpl::string<> type;
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Tag>
|
||||
struct advance_impl;
|
||||
|
||||
template<>
|
||||
struct advance_impl<string_iterator_tag>
|
||||
{
|
||||
template<typename Iterator, typename N>
|
||||
struct apply
|
||||
{
|
||||
typedef string_iterator<
|
||||
typename Iterator::string_type
|
||||
, Iterator::index + N::value
|
||||
> 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> \
|
||||
{ \
|
||||
typedef mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)> string; \
|
||||
typedef std::bidirectional_iterator_tag category; \
|
||||
typedef \
|
||||
typename mpl::if_c< \
|
||||
(BOOST_MPL_MULTICHAR_LENGTH(BOOST_PP_CAT(C, n)) == J + 1) \
|
||||
, mpl::string_iterator<string, n + 1, 0> \
|
||||
, mpl::string_iterator<string, n, J + 1> \
|
||||
>::type \
|
||||
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> \
|
||||
{ \
|
||||
typedef mpl::string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)> string; \
|
||||
typedef std::bidirectional_iterator_tag category; \
|
||||
typedef \
|
||||
typename mpl::if_c< \
|
||||
(BOOST_MPL_MULTICHAR_LENGTH(BOOST_PP_CAT(C, n)) == 1) \
|
||||
, mpl::string_iterator<string, n + 1, 0> \
|
||||
, mpl::string_iterator<string, n, 1> \
|
||||
>::type \
|
||||
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; \
|
||||
};
|
||||
|
||||
template<typename Tag>
|
||||
struct distance_impl;
|
||||
BOOST_PP_REPEAT(BOOST_MPL_STRING_MAX_PARAMS, M0, ~)
|
||||
#undef M0
|
||||
|
||||
template<>
|
||||
struct distance_impl<string_iterator_tag>
|
||||
{
|
||||
template<typename First, typename Last>
|
||||
struct apply
|
||||
{
|
||||
typedef mpl::long_<(long)Last::index - (long)First::index> type;
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Sequence, unsigned long N>
|
||||
struct string_iterator
|
||||
: Sequence::template at<N>
|
||||
{
|
||||
typedef string_iterator_tag tag;
|
||||
typedef std::random_access_iterator_tag category;
|
||||
typedef Sequence string_type;
|
||||
static unsigned long const index = N;
|
||||
typedef string_iterator<Sequence, N+1> next;
|
||||
typedef string_iterator<Sequence, N-1> prior;
|
||||
};
|
||||
|
||||
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned int C)>
|
||||
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned C)>
|
||||
struct string
|
||||
{
|
||||
/// INTERNAL ONLY
|
||||
static unsigned int const front_ = C0;
|
||||
/// INTERNAL ONLY
|
||||
static unsigned int const back_ = BOOST_PP_CAT(C, BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS));
|
||||
/// INTERNAL ONLY
|
||||
typedef string<BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)> rest_;
|
||||
enum
|
||||
{
|
||||
front_ = C0
|
||||
, back_ = BOOST_PP_CAT(C, BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS))
|
||||
};
|
||||
|
||||
typedef string type;
|
||||
|
||||
typedef string_tag tag;
|
||||
|
||||
static std::size_t const size = BOOST_MPL_MULTICHAR_LENGTH(C0) + rest_::size;
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1400)
|
||||
private:
|
||||
/// INTERNAL ONLY
|
||||
template<unsigned long Pos, bool B>
|
||||
struct at_impl
|
||||
: boost::mpl::char_<BOOST_MPL_MULTICHAR_AT(C0,Pos)>
|
||||
{};
|
||||
|
||||
/// INTERNAL ONLY
|
||||
template<unsigned long Pos>
|
||||
struct at_impl<Pos, false>
|
||||
: rest_::template at<Pos-BOOST_MPL_MULTICHAR_LENGTH(C0)>
|
||||
{};
|
||||
|
||||
public:
|
||||
template<unsigned long Pos>
|
||||
struct at
|
||||
: at_impl<Pos, (Pos < BOOST_MPL_MULTICHAR_LENGTH(C0))>
|
||||
{};
|
||||
#else
|
||||
template<unsigned long Pos, bool B = (Pos < BOOST_MPL_MULTICHAR_LENGTH(C0))>
|
||||
struct at
|
||||
: boost::mpl::char_<BOOST_MPL_MULTICHAR_AT(C0,Pos)>
|
||||
{};
|
||||
|
||||
template<unsigned long Pos>
|
||||
struct at<Pos, false>
|
||||
: rest_::template at<Pos-BOOST_MPL_MULTICHAR_LENGTH(C0)>
|
||||
{};
|
||||
#endif
|
||||
|
||||
static char const c_str[];
|
||||
typedef string type;
|
||||
typedef string_tag tag;
|
||||
};
|
||||
|
||||
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned int C)>
|
||||
char const string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>::c_str[] =
|
||||
namespace aux_
|
||||
{
|
||||
#define M0(z, n, data) at<n>::value
|
||||
BOOST_PP_ENUM(BOOST_MPL_STRING_MAX_LENGTH, M0, ~)
|
||||
#undef M0
|
||||
, '\0' // to ensure the string is null-terminated
|
||||
};
|
||||
|
||||
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned int C)>
|
||||
std::size_t const string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>::size;
|
||||
|
||||
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned int C)>
|
||||
unsigned int const string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>::front_;
|
||||
|
||||
template<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, unsigned int C)>
|
||||
unsigned int const string<BOOST_PP_ENUM_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C)>::back_;
|
||||
|
||||
template<>
|
||||
struct string<>
|
||||
{
|
||||
/// INTERNAL ONLY
|
||||
static unsigned int const front_ = 0;
|
||||
/// INTERNAL ONLY
|
||||
static unsigned int const back_ = 0;
|
||||
/// INTERNAL ONLY
|
||||
typedef string rest_;
|
||||
|
||||
typedef string type;
|
||||
|
||||
typedef string_tag tag;
|
||||
|
||||
static std::size_t const size = 0;
|
||||
|
||||
template<unsigned long>
|
||||
struct at
|
||||
: boost::mpl::char_<'\0'>
|
||||
template<typename It, typename End>
|
||||
struct next_unless
|
||||
: mpl::next<It>
|
||||
{};
|
||||
|
||||
static char const c_str[];
|
||||
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_STRING_MAX_LENGTH, M0, ~)
|
||||
#undef M0
|
||||
|
||||
typedef c_str type;
|
||||
static char const value[];
|
||||
};
|
||||
|
||||
char const string<>::c_str[] = {'\0'};
|
||||
std::size_t const string<>::size;
|
||||
unsigned int const string<>::front_;
|
||||
unsigned int const string<>::back_;
|
||||
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_STRING_MAX_LENGTH, M0, ~)
|
||||
#undef M0
|
||||
'\0'
|
||||
};
|
||||
|
||||
}} // namespace boost
|
||||
|
||||
|
||||
Reference in New Issue
Block a user