diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/spirit/test/x3/symbols3.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/spirit/test/x3/symbols3.cpp')
-rw-r--r-- | src/boost/libs/spirit/test/x3/symbols3.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/boost/libs/spirit/test/x3/symbols3.cpp b/src/boost/libs/spirit/test/x3/symbols3.cpp new file mode 100644 index 00000000..d732ca3d --- /dev/null +++ b/src/boost/libs/spirit/test/x3/symbols3.cpp @@ -0,0 +1,86 @@ +/*============================================================================= + Copyright (c) 2013 Carl Barron + Copyright (c) 2015 Joel de Guzman + + 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/detail/lightweight_test.hpp> +#include <boost/spirit/home/x3.hpp> +#include <boost/fusion/include/at.hpp> +#include <boost/fusion/include/vector.hpp> +#include <boost/fusion/include/adapt_struct.hpp> +#include <boost/mpl/int.hpp> +#include <boost/optional.hpp> + +#include <iostream> +#include <numeric> +#include <vector> +#include "test.hpp" + +struct roman +{ + boost::optional<int> a; + boost::optional<int> b; + boost::optional<int> c; +}; + +BOOST_FUSION_ADAPT_STRUCT(roman, + a, b, c +) + +int eval(roman const & c) +{ + return c.a.get_value_or(0) + c.b.get_value_or(0) + c.c.get_value_or(0); +} + +int +main() +{ + using spirit_test::test; + using spirit_test::test_attr; + using boost::spirit::x3::symbols; + + { // construction from initializer-list + symbols<int> const ones = + { + {"I", 1}, {"II", 2}, {"III", 3}, {"IV", 4}, + {"V", 5}, {"VI", 6}, {"VII", 7}, {"VIII", 8}, + {"IX", 9} + }; + symbols<int> const tens = + { + {"X", 10}, {"XX", 20}, {"XXX", 30}, {"XL", 40}, + {"L", 50}, {"LX", 60}, {"LXX", 70}, {"LXXX", 80}, + {"XC", 90} + }; + symbols<int> const hundreds + { + {"C", 100}, {"CC", 200}, {"CCC", 300}, {"CD", 400}, + {"D", 500}, {"DC", 600}, {"DCC", 700}, {"DCCC", 800}, + {"CM", 900} + }; + + auto number = -hundreds >> -tens >> -ones; + + roman r; + BOOST_TEST((test_attr("CDXLII", number, r))); + BOOST_TEST(eval(r) == 442); + } + + { // construction from initializer-list without attribute + symbols<> foo = {"a1", "a2", "a3"}; + + BOOST_TEST((test("a3", foo))); + } + + { // assignment from initializer-list + symbols<> foo; + foo = {"a1", "a2", "a3"}; + + BOOST_TEST((test("a3", foo))); + } + + return boost::report_errors(); +} |