// Copyright (c) 2019-2021 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) #include #include template struct constrained_template { constrained_template() = default; template < class U = T, std::enable_if_t< std::is_constructible::value || sizeof(decltype(T{std::declval()})) , bool> = false> constexpr constrained_template(U&& val) : value_{std::forward(val)} {} T value_; }; struct int_element { int value_; }; struct aggregate_constrained { constrained_template a; constrained_template b; }; int main() { static_assert( std::is_same< boost::pfr::tuple_element_t<0, aggregate_constrained>, constrained_template >::value, "Precise reflection with template constructors fails to work" ); static_assert( std::is_same< boost::pfr::tuple_element_t<1, aggregate_constrained>, constrained_template >::value, "Precise reflection with template constructors fails to work" ); short s = 3; aggregate_constrained aggr{s, 4}; return boost::pfr::get<1>(aggr).value_.value_ - 4; }