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/spirit/home/x3.hpp>
8#include <boost/spirit/home/x3/support/ast/variant.hpp>
9
10#include <string>
11#include <iostream>
12#include "test.hpp"
13
14namespace x3 = boost::spirit::x3;
15
16struct none {};
17
18using variant = x3::variant<
19 none
20 , bool
21 , std::string
22 , int
23 , double
24 >;
25
26struct ast : variant
27{
28 using variant::variant;
29 using variant::operator=;
30
31 ast(char const* s)
32 : variant(std::string{s})
33 {}
34
35 ast& operator=(char const* s)
36 {
37 variant::operator=(rhs: std::string{s});
38 return *this;
39 }
40};
41
42int
43main()
44{
45 {
46 ast v{123};
47 BOOST_TEST(boost::get<int>(v) == 123);
48
49 v = "test";
50 BOOST_TEST(boost::get<std::string>(v) == "test");
51
52 v = true;
53 BOOST_TEST(boost::get<bool>(v) == true);
54 }
55 return boost::report_errors();
56}
57

source code of boost/libs/spirit/test/x3/x3_variant.cpp