1 // Copyright (c) 2016-2020 Antony Polukhin
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)
7 #ifndef BOOST_PFR_DETAIL_CORE17_HPP
8 #define BOOST_PFR_DETAIL_CORE17_HPP
10 #include <boost/pfr/detail/core17_generated.hpp>
11 #include <boost/pfr/detail/fields_count.hpp>
12 #include <boost/pfr/detail/for_each_field_impl.hpp>
13 #include <boost/pfr/detail/rvalue_t.hpp>
15 namespace boost { namespace pfr { namespace detail {
17 #ifndef _MSC_VER // MSVC fails to compile the following code, but compiles the structured bindings in core17_generated.hpp
18 struct do_not_define_std_tuple_size_for_me {
23 constexpr bool do_structured_bindings_work() noexcept { // ******************************************* IN CASE OF ERROR READ THE FOLLOWING LINES IN boost/pfr/detail/core17.hpp FILE:
25 const auto& [a] = val; // ******************************************* IN CASE OF ERROR READ THE FOLLOWING LINES IN boost/pfr/detail/core17.hpp FILE:
27 /****************************************************************************
29 * It looks like your compiler or Standard Library can not handle C++17
30 * structured bindings.
32 * Workaround: Define BOOST_PFR_USE_CPP17 to 0
33 * It will disable the C++17 features for Boost.PFR library.
35 * Sorry for the inconvenience caused.
37 ****************************************************************************/
43 do_structured_bindings_work<do_not_define_std_tuple_size_for_me>(),
44 "====================> Boost.PFR: Your compiler can not handle C++17 structured bindings. Read the above comments for workarounds."
46 #endif // #ifndef _MSC_VER
49 constexpr auto tie_as_tuple(T& val) noexcept {
51 !std::is_union<T>::value,
52 "====================> Boost.PFR: For safety reasons it is forbidden to reflect unions. See `Reflection of unions` section in the docs for more info."
54 typedef size_t_<boost::pfr::detail::fields_count<T>()> fields_count_tag;
55 return boost::pfr::detail::tie_as_tuple(val, fields_count_tag{});
58 template <class T, class F, std::size_t... I>
59 void for_each_field_dispatcher(T& t, F&& f, std::index_sequence<I...>) {
61 !std::is_union<T>::value,
62 "====================> Boost.PFR: For safety reasons it is forbidden to reflect unions. See `Reflection of unions` section in the docs for more info."
65 detail::tie_as_tuple(t)
69 }}} // namespace boost::pfr::detail
71 #endif // BOOST_PFR_DETAIL_CORE17_HPP