]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #ifndef BOOST_METAPARSE_V1_IMPL_CONCAT_HPP |
2 | #define BOOST_METAPARSE_V1_IMPL_CONCAT_HPP | |
3 | ||
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) | |
8 | ||
9 | #include <boost/metaparse/config.hpp> | |
10 | #include <boost/metaparse/v1/fwd/string.hpp> | |
11 | ||
12 | #include <boost/preprocessor/arithmetic/dec.hpp> | |
13 | #include <boost/preprocessor/arithmetic/inc.hpp> | |
14 | #include <boost/preprocessor/arithmetic/mul.hpp> | |
15 | #include <boost/preprocessor/arithmetic/sub.hpp> | |
16 | #include <boost/preprocessor/cat.hpp> | |
17 | #include <boost/preprocessor/punctuation/comma_if.hpp> | |
18 | #include <boost/preprocessor/repetition/enum.hpp> | |
19 | #include <boost/preprocessor/repetition/enum_params.hpp> | |
20 | ||
21 | namespace boost | |
22 | { | |
23 | namespace metaparse | |
24 | { | |
25 | namespace v1 | |
26 | { | |
27 | namespace impl | |
28 | { | |
29 | template <class A, class B> | |
30 | struct concat; | |
31 | ||
32 | #ifdef BOOST_METAPARSE_VARIADIC_STRING | |
33 | template <char... As, char... Bs> | |
34 | struct concat<string<As...>, string<Bs...>> : string<As..., Bs...> {}; | |
35 | #else | |
36 | template <class A, class B> | |
37 | struct concat_impl; | |
38 | ||
39 | #ifdef BOOST_METAPARSE_ARG | |
40 | # error BOOST_METAPARSE_ARG already defined | |
41 | #endif | |
42 | #define BOOST_METAPARSE_ARG(z, n, unused) \ | |
43 | BOOST_PP_CAT(B, BOOST_PP_INC(n)) | |
44 | ||
45 | #ifdef BOOST_METAPARSE_CONCAT | |
46 | # error BOOST_METAPARSE_CONCAT already defined | |
47 | #endif | |
48 | #define BOOST_METAPARSE_CONCAT(z, n, unused) \ | |
49 | template < \ | |
50 | BOOST_PP_ENUM_PARAMS(n, int A) BOOST_PP_COMMA_IF(n) \ | |
51 | BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int B) \ | |
52 | > \ | |
53 | struct \ | |
54 | concat_impl< \ | |
55 | string< \ | |
56 | BOOST_PP_ENUM_PARAMS(n, A) \ | |
57 | BOOST_PP_COMMA_IF( \ | |
58 | BOOST_PP_MUL( \ | |
59 | BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_STRING_SIZE, n), \ | |
60 | n \ | |
61 | ) \ | |
62 | ) \ | |
63 | BOOST_PP_ENUM( \ | |
64 | BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_STRING_SIZE, n), \ | |
65 | BOOST_NO_CHAR BOOST_PP_TUPLE_EAT(3), \ | |
66 | ~ \ | |
67 | ) \ | |
68 | >, \ | |
69 | string< \ | |
70 | BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, B) \ | |
71 | > \ | |
72 | > : \ | |
73 | concat< \ | |
74 | string<BOOST_PP_ENUM_PARAMS(n, A) BOOST_PP_COMMA_IF(n) B0>, \ | |
75 | string< \ | |
76 | BOOST_PP_ENUM( \ | |
77 | BOOST_PP_DEC(BOOST_METAPARSE_LIMIT_STRING_SIZE), \ | |
78 | BOOST_METAPARSE_ARG, \ | |
79 | ~ \ | |
80 | ) \ | |
81 | > \ | |
82 | > \ | |
83 | {}; | |
84 | ||
85 | BOOST_PP_REPEAT( | |
86 | BOOST_METAPARSE_LIMIT_STRING_SIZE, | |
87 | BOOST_METAPARSE_CONCAT, | |
88 | ~ | |
89 | ) | |
90 | ||
91 | #undef BOOST_METAPARSE_ARG | |
92 | #undef BOOST_METAPARSE_CONCAT | |
93 | ||
94 | template <class S> | |
95 | struct concat<S, string<> > : S {}; | |
96 | ||
97 | template <class A, class B> | |
98 | struct concat : concat_impl<A, B> {}; | |
99 | #endif | |
100 | } | |
101 | } | |
102 | } | |
103 | } | |
104 | ||
105 | #endif | |
106 |