Blame view

3rdparty/boost_1_81_0/libs/variant/test/issue53.cpp 1.35 KB
73ef4ff3   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  //-----------------------------------------------------------------------------
  // boost-libs variant/test/issue53.cpp source file
  // See http://www.boost.org for updates, documentation, and revision history.
  //-----------------------------------------------------------------------------
  //
  // Copyright (c) 2019-2022 Antony Polukhin
  //
  // 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)
  
  // Test case from https://github.com/boostorg/variant/issues/53
  
  #include <boost/variant.hpp>
  #include <boost/thread/lock_guard.hpp> // this line was causing problems on MSVC
  
  #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  
  struct spanac {};
  
  struct ceapa{
      double a,b;
  };
  
  typedef boost::variant<spanac, ceapa> var_t;
  
  struct visitor_t : public boost::static_visitor<bool> {
      bool operator() (const spanac&) const {
          return true;
      }
  
      bool operator() (const ceapa&) const {
          return false;
      }
  
  private:
      double a, b;
  };
  
  var_t get(int k) {
      if (k)
          return spanac();
      else
          return ceapa();
  }
  
  int main(int argc, const char** argv) {
      visitor_t v;
  
      bool result = boost::apply_visitor(v, get(argc - 1));
      (void)result;
  }
  
  #else // #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  
  int main() {}
  
  #endif // #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES