• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //-----------------------------------------------------------------------------
2 // boost-libs variant/test/issue53.cpp source file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
5 //
6 // Copyright (c) 2019-2020 Antony Polukhin
7 //
8 // Distributed under the Boost Software License, Version 1.0. (See
9 // accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11 
12 // Test case from https://github.com/boostorg/variant/issues/53
13 
14 #include <boost/variant.hpp>
15 #include <boost/thread/lock_guard.hpp> // this line was causing problems on MSVC
16 
17 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
18 
19 struct spanac {};
20 
21 struct ceapa{
22     double a,b;
23 };
24 
25 typedef boost::variant<spanac, ceapa> var_t;
26 
27 struct visitor_t : public boost::static_visitor<bool> {
operator ()visitor_t28     bool operator() (const spanac&) const {
29         return true;
30     }
31 
operator ()visitor_t32     bool operator() (const ceapa&) const {
33         return false;
34     }
35 
36 private:
37     double a, b;
38 };
39 
get(int k)40 var_t get(int k) {
41     if (k)
42         return spanac();
43     else
44         return ceapa();
45 }
46 
main(int argc,const char ** argv)47 int main(int argc, const char** argv) {
48     visitor_t v;
49 
50     bool result = boost::apply_visitor(v, get(argc - 1));
51     (void)result;
52 }
53 
54 #else // #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
55 
main()56 int main() {}
57 
58 #endif // #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
59