]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #ifndef BOOST_METAPARSE_V1_IMPL_STRING_AT_HPP |
2 | #define BOOST_METAPARSE_V1_IMPL_STRING_AT_HPP | |
3 | ||
4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. | |
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/static_assert.hpp> | |
11 | #include <boost/metaparse/v1/impl/no_char.hpp> | |
12 | ||
13 | namespace boost | |
14 | { | |
15 | namespace metaparse | |
16 | { | |
17 | namespace v1 | |
18 | { | |
19 | namespace impl | |
20 | { | |
21 | template <int MaxLen, int Len, class T> | |
22 | BOOST_CONSTEXPR int string_at(const T (&s)[Len], int n) | |
23 | { | |
24 | // "MaxLen + 1" adds the \0 character of the string literal to the | |
25 | // limit | |
26 | BOOST_STATIC_ASSERT((Len <= MaxLen + 1)); | |
27 | return n >= Len - 1 ? BOOST_NO_CHAR : s[n]; | |
28 | } | |
29 | } | |
30 | } | |
31 | } | |
32 | } | |
33 | ||
34 | #ifdef BOOST_METAPARSE_V1_STRING_AT | |
35 | # error BOOST_METAPARSE_V1_STRING_AT already defined | |
36 | #endif | |
37 | #define BOOST_METAPARSE_V1_STRING_AT \ | |
38 | ::boost::metaparse::v1::impl::string_at<BOOST_METAPARSE_LIMIT_STRING_SIZE> | |
39 | ||
40 | #endif | |
41 |