1 // Copyright (c) 2016
2 // Mikhail Maximov
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
8 #include "boost/config.hpp"
9 #include "boost/core/lightweight_test.hpp"
10 
11 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET)
12 // Test is based on reported issues:
13 // https://svn.boost.org/trac/boost/ticket/12508
14 // https://svn.boost.org/trac/boost/ticket/12645
15 // Following hash function was not found at compile time,
16 // because boost::variant construction from boost::recursive_variant_
17 // was forbidden.
18 
19 #include <unordered_set>
20 
21 #include "boost/variant.hpp"
22 
23 struct hash;
24 
25 using int_t = int;
26 
27 template <typename T>
28 using basic_set_t = std::unordered_set<T, hash>;
29 
30 using value_t = boost::make_recursive_variant<
31 		int_t,
32 		basic_set_t<boost::recursive_variant_>
33 >::type;
34 
35 using set_t = basic_set_t<value_t>;
36 
37 struct hash
38 {
operator ()hash39     size_t operator()(const value_t&) const
40     {
41       return 0;
42     }
43 };
44 
run()45 void run()
46 {
47     set_t s;
48     int_t i = 3;
49     value_t v = i;
50     auto emplace_result = s.emplace(v); // raises error above
51     BOOST_TEST(emplace_result.second);
52     v = s;
53     const set_t& check_set = boost::get<set_t>(v);
54     BOOST_TEST(!check_set.empty());
55     for (const auto& check_v : check_set) {
56       BOOST_TEST(s.find(check_v) != s.end());
57     }
58     for (const auto& check_v : s) {
59       BOOST_TEST(check_set.find(check_v) != check_set.end());
60     }
61 }
62 
63 #else // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET)
64 // if no unordered_set and template aliases - does nothing
run()65 void run() {}
66 #endif
67 
main()68 int main()
69 {
70    run();
71    return boost::report_errors();
72 }
73 
74