issue42.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //-----------------------------------------------------------------------------
  2. // boost-libs variant/test/issue42.cpp source file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2018-2019 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. // Test case from https://github.com/boostorg/variant/issues/42
  12. #include <boost/variant.hpp>
  13. #include <map>
  14. #include <memory>
  15. #include <vector>
  16. #ifdef BOOST_NO_CXX11_SMART_PTR
  17. template <class T> struct shared_ptr_like {};
  18. typedef shared_ptr_like<boost::recursive_variant_> ptr_t;
  19. #else
  20. typedef std::shared_ptr<boost::recursive_variant_> ptr_t;
  21. #endif
  22. template <class F>
  23. class func{};
  24. int main() {
  25. typedef boost::make_recursive_variant<
  26. int,
  27. ptr_t
  28. >::type node;
  29. node x = 1;
  30. (void)x;
  31. typedef boost::make_recursive_variant<
  32. std::string, int, double, bool,
  33. ptr_t,
  34. std::map<const std::string, boost::recursive_variant_>,
  35. std::vector<boost::recursive_variant_>
  36. >::type node2;
  37. node2 x2 = 1;
  38. (void)x2;
  39. typedef boost::make_recursive_variant<
  40. int,
  41. func<boost::recursive_variant_(*)(boost::recursive_variant_&, const boost::recursive_variant_&)>,
  42. boost::recursive_variant_&(*)(boost::recursive_variant_, boost::recursive_variant_*),
  43. ptr_t
  44. >::type node3;
  45. node3 x3 = func<node3(*)(node3&, const node3&)>();
  46. (void)x3;
  47. }