1 #ifndef BOOST_METAPARSE_V1_IMPL_SPLIT_AT_C_HPP
2 #define BOOST_METAPARSE_V1_IMPL_SPLIT_AT_C_HPP
4 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2013.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/metaparse/config.hpp>
10 #include <boost/metaparse/v1/fwd/string.hpp>
11 #include <boost/metaparse/v1/impl/push_front_c.hpp>
13 #include <boost/preprocessor/arithmetic/add.hpp>
14 #include <boost/preprocessor/arithmetic/sub.hpp>
15 #include <boost/preprocessor/cat.hpp>
16 #include <boost/preprocessor/repetition/enum.hpp>
17 #include <boost/preprocessor/repetition/enum_params.hpp>
18 #include <boost/preprocessor/repetition/repeat.hpp>
20 #include <boost/mpl/pair.hpp>
30 template <int N, class S>
33 #ifdef BOOST_METAPARSE_VARIADIC_STRING
34 template <int N, char C, char... Cs>
35 struct split_at_c<N, string<C, Cs...>> :
37 typename push_front_c<
38 typename split_at_c<N - 1, string<Cs...>>::type::first,
41 typename split_at_c<N - 1, string<Cs...>>::type::second
45 template <char C, char... Cs>
46 struct split_at_c<0, string<C, Cs...>> :
47 boost::mpl::pair<string<>, string<C, Cs...>>
51 struct split_at_c<0, S> : boost::mpl::pair<string<>, S> {};
53 #ifdef BOOST_METAPARSE_ARG
54 # error BOOST_METAPARSE_ARG already defined
56 #define BOOST_METAPARSE_ARG(z, n, d) BOOST_PP_CAT(C, BOOST_PP_ADD(n, d))
58 #ifdef BOOST_METAPARSE_SPLIT_AT
59 # error BOOST_METAPARSE_SPLIT_AT already defined
61 #define BOOST_METAPARSE_SPLIT_AT(z, n, unused) \
63 BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int C) \
68 string<BOOST_PP_ENUM_PARAMS( \
69 BOOST_METAPARSE_LIMIT_STRING_SIZE, C) \
73 string<BOOST_PP_ENUM_PARAMS(n, C)>, \
76 BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_STRING_SIZE, n), \
77 BOOST_METAPARSE_ARG, \
85 BOOST_METAPARSE_LIMIT_STRING_SIZE,
86 BOOST_METAPARSE_SPLIT_AT,
90 #undef BOOST_METAPARSE_SPLIT_AT
91 #undef BOOST_METAPARSE_ARG