• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2016 Joel de Guzman
3 
4     Distributed under the Boost Software License, Version 1.0. (See accompanying
5     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #include <boost/detail/lightweight_test.hpp>
8 #include <boost/spirit/home/x3.hpp>
9 #include <boost/spirit/home/x3/support/ast/variant.hpp>
10 
11 #include <string>
12 #include <iostream>
13 #include "test.hpp"
14 
15 namespace x3 = boost::spirit::x3;
16 
17 struct none {};
18 
19 using variant = x3::variant<
20         none
21       , bool
22       , std::string
23       , int
24       , double
25     >;
26 
27 struct ast : variant
28 {
29     using variant::variant;
30     using variant::operator=;
31 
astast32     ast(char const* s)
33       : variant(std::string{s})
34     {}
35 
operator =ast36     ast& operator=(char const* s)
37     {
38         variant::operator=(std::string{s});
39         return *this;
40     }
41 };
42 
43 int
main()44 main()
45 {
46     {
47         ast v{123};
48         BOOST_TEST(boost::get<int>(v) == 123);
49 
50         v = "test";
51         BOOST_TEST(boost::get<std::string>(v) == "test");
52 
53         v = true;
54         BOOST_TEST(boost::get<bool>(v) == true);
55     }
56     return boost::report_errors();
57 }
58