mirror of
https://github.com/boostorg/metaparse.git
synced 2026-01-19 04:22:10 +00:00
Add BOOST_METAPARSE_STRING_VALUE
This commit is contained in:
43
doc/BOOST_METAPARSE_STRING_VALUE.qbk
Normal file
43
doc/BOOST_METAPARSE_STRING_VALUE.qbk
Normal file
@@ -0,0 +1,43 @@
|
||||
[#BOOST_METAPARSE_STRING_VALUE]
|
||||
[section BOOST_METAPARSE_STRING_VALUE]
|
||||
|
||||
[h1 Synopsis]
|
||||
|
||||
#define BOOST_METAPARSE_STRING_VALUE(s) \
|
||||
// unspecified
|
||||
|
||||
This is a macro.
|
||||
|
||||
[table Arguments
|
||||
[[Name] [Type]]
|
||||
[[`s`] [string literal]]
|
||||
]
|
||||
|
||||
[h1 Description]
|
||||
|
||||
This is a convenience macro for creating instances of the string types created
|
||||
using [link BOOST_METAPARSE_STRING `BOOST_METAPARSE_STRING`].
|
||||
|
||||
[h1 Header]
|
||||
|
||||
#include <boost/metaparse/string_value.hpp>
|
||||
|
||||
[h1 Expression semantics]
|
||||
|
||||
For any `s` string literal
|
||||
|
||||
BOOST_METAPARSE_STRING_VALUE(s)
|
||||
|
||||
is equivalent to
|
||||
|
||||
BOOST_METAPARSE_STRING(s){}
|
||||
|
||||
[h1 Example]
|
||||
|
||||
#define BOOST_METAPARSE_LIMIT_STRING_SIZE 8
|
||||
#include <boost/metaparse/string_value.hpp>
|
||||
|
||||
constexpr auto s = BOOST_METAPARSE_STRING_VALUE("Hello");
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -176,6 +176,7 @@ choosing among the `fold*` parsers.
|
||||
* [link string string]
|
||||
* [link string_tag string_tag]
|
||||
* [link BOOST_METAPARSE_STRING BOOST_METAPARSE_STRING]
|
||||
* [link BOOST_METAPARSE_STRING_VALUE BOOST_METAPARSE_STRING_VALUE]
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -256,6 +257,7 @@ classes.
|
||||
[include always.qbk]
|
||||
[include BOOST_METAPARSE_DEFINE_ERROR.qbk]
|
||||
[include BOOST_METAPARSE_STRING.qbk]
|
||||
[include BOOST_METAPARSE_STRING_VALUE.qbk]
|
||||
[include BOOST_METAPARSE_VERSION.qbk]
|
||||
[include boxed_value.qbk]
|
||||
[include build_parser.qbk]
|
||||
|
||||
17
include/boost/metaparse/string_value.hpp
Normal file
17
include/boost/metaparse/string_value.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright Abel Sinkovics (abel@sinkovics.hu) 2021.
|
||||
// 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)
|
||||
|
||||
#ifndef BOOST_METAPARSE_STRING_VALUE_HPP
|
||||
#define BOOST_METAPARSE_STRING_VALUE_HPP
|
||||
|
||||
#include <boost/metaparse/v1/string_value.hpp>
|
||||
|
||||
#ifdef BOOST_METAPARSE_STRING_VALUE
|
||||
# error BOOST_METAPARSE_STRING_VALUE already defined
|
||||
#endif
|
||||
#define BOOST_METAPARSE_STRING_VALUE BOOST_METAPARSE_V1_STRING_VALUE
|
||||
|
||||
#endif
|
||||
|
||||
20
include/boost/metaparse/v1/string_value.hpp
Normal file
20
include/boost/metaparse/v1/string_value.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef BOOST_METAPARSE_V1_STRING_VALUE_HPP
|
||||
#define BOOST_METAPARSE_V1_STRING_VALUE_HPP
|
||||
|
||||
// Copyright Abel Sinkovics (abel@sinkovics.hu) 2021.
|
||||
// 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)
|
||||
|
||||
#include <boost/metaparse/v1/string.hpp>
|
||||
|
||||
#ifdef BOOST_METAPARSE_V1_STRING_VALUE
|
||||
#error BOOST_METAPARSE_V1_STRING_VALUE already defined
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_METAPARSE_V1_STRING
|
||||
#define BOOST_METAPARSE_V1_STRING_VALUE(s) (BOOST_METAPARSE_V1_STRING(s){})
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -101,6 +101,7 @@ test-suite metaparse-unit-tests :
|
||||
[ run string.cpp ]
|
||||
[ compile string_iterator_tag.cpp ]
|
||||
[ compile string_tag.cpp ]
|
||||
[ compile string_value.cpp ]
|
||||
[ compile swap.cpp ]
|
||||
[ compile token.cpp ]
|
||||
[ compile-fail too_long_string.cpp ]
|
||||
|
||||
27
test/string_value.cpp
Normal file
27
test/string_value.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright Abel Sinkovics (abel@sinkovics.hu) 2021.
|
||||
// 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)
|
||||
|
||||
#define BOOST_TEST_MODULE string_value
|
||||
|
||||
#include <boost/metaparse/string_value.hpp>
|
||||
#include <boost/metaparse/string.hpp>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#if BOOST_METAPARSE_STD >= 2011
|
||||
#include <type_traits>
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_string_value)
|
||||
{
|
||||
#if BOOST_METAPARSE_STD >= 2011
|
||||
auto foo = BOOST_METAPARSE_STRING_VALUE("foo");
|
||||
|
||||
BOOST_MPL_ASSERT((
|
||||
std::is_same<BOOST_METAPARSE_STRING("foo"), decltype(foo)>
|
||||
));
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user