• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2019-2021 Antony Polukhin
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include <type_traits>
7 
8 #include <boost/pfr/core.hpp>
9 
10 template <class T>
11 struct unconstrained_template {
12     unconstrained_template() = default;
13     unconstrained_template(const unconstrained_template&) = default;
14     unconstrained_template(unconstrained_template&&) = default;
15     unconstrained_template& operator=(const unconstrained_template&) = default;
16     unconstrained_template& operator=(unconstrained_template&&) = default;
17 
18     template <class U>
unconstrained_templateunconstrained_template19     constexpr unconstrained_template(const U& val)
20         : value_{val}
21     {}
22 
23     T value_{};
24 };
25 
26 struct int_element {
27     int value_;
28 };
29 
30 
31 struct aggregate_unconstrained {
32     unconstrained_template<int> a;
33     unconstrained_template<int_element> b;
34 };
35 
main()36 int main() {
37     using sanity = decltype(aggregate_unconstrained{
38       boost::pfr::detail::ubiq_lref_constructor{0},
39       boost::pfr::detail::ubiq_lref_constructor{1},
40     });
41     static_assert(
42         std::is_same<
43             sanity, aggregate_unconstrained
44         >::value,
45         "Precise reflection with template constructors sanity check fails"
46     );
47 
48     boost::pfr::detail::enable_if_constructible_helper_t<aggregate_unconstrained, 2> foo;
49     (void)foo;
50 
51     static_assert(
52         std::is_same<
53             boost::pfr::tuple_element_t<0, aggregate_unconstrained>,
54             unconstrained_template<int>
55         >::value,
56         "Precise reflection with template constructors fails to work"
57     );
58 
59     static_assert(
60         std::is_same<
61             boost::pfr::tuple_element_t<1, aggregate_unconstrained>,
62             unconstrained_template<int_element>
63         >::value,
64         "Precise reflection with template constructors fails to work"
65     );
66 
67     aggregate_unconstrained aggr{3, 4};
68     return boost::pfr::get<1>(aggr).value_.value_ - 4;
69 }
70