diff --git a/doc/BOOST_METAPARSE_STRING_VALUE.qbk b/doc/BOOST_METAPARSE_STRING_VALUE.qbk new file mode 100644 index 0000000..0c14e4d --- /dev/null +++ b/doc/BOOST_METAPARSE_STRING_VALUE.qbk @@ -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 + +[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 + + constexpr auto s = BOOST_METAPARSE_STRING_VALUE("Hello"); + +[endsect] + diff --git a/doc/reference.qbk b/doc/reference.qbk index 73f3c56..ddc2575 100644 --- a/doc/reference.qbk +++ b/doc/reference.qbk @@ -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] diff --git a/include/boost/metaparse/string_value.hpp b/include/boost/metaparse/string_value.hpp new file mode 100644 index 0000000..27b56d3 --- /dev/null +++ b/include/boost/metaparse/string_value.hpp @@ -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 + +#ifdef BOOST_METAPARSE_STRING_VALUE +# error BOOST_METAPARSE_STRING_VALUE already defined +#endif +#define BOOST_METAPARSE_STRING_VALUE BOOST_METAPARSE_V1_STRING_VALUE + +#endif + diff --git a/include/boost/metaparse/v1/string_value.hpp b/include/boost/metaparse/v1/string_value.hpp new file mode 100644 index 0000000..6edc6ae --- /dev/null +++ b/include/boost/metaparse/v1/string_value.hpp @@ -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 + +#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 + diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index aa8eee8..2ac4b8b 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 ] diff --git a/test/string_value.cpp b/test/string_value.cpp new file mode 100644 index 0000000..3dd6bd9 --- /dev/null +++ b/test/string_value.cpp @@ -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 +#include + +#include + +#if BOOST_METAPARSE_STD >= 2011 +#include +#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 + )); +#endif +} +