]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/pfr/detail/core17.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / pfr / detail / core17.hpp
1 // Copyright (c) 2016-2020 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
7 #ifndef BOOST_PFR_DETAIL_CORE17_HPP
8 #define BOOST_PFR_DETAIL_CORE17_HPP
9
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>
14
15 namespace boost { namespace pfr { namespace detail {
16
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 {
19 bool test1 = true;
20 };
21
22 template <class T>
23 constexpr bool do_structured_bindings_work() noexcept { // ******************************************* IN CASE OF ERROR READ THE FOLLOWING LINES IN boost/pfr/detail/core17.hpp FILE:
24 T val{};
25 const auto& [a] = val; // ******************************************* IN CASE OF ERROR READ THE FOLLOWING LINES IN boost/pfr/detail/core17.hpp FILE:
26
27 /****************************************************************************
28 *
29 * It looks like your compiler or Standard Library can not handle C++17
30 * structured bindings.
31 *
32 * Workaround: Define BOOST_PFR_USE_CPP17 to 0
33 * It will disable the C++17 features for Boost.PFR library.
34 *
35 * Sorry for the inconvenience caused.
36 *
37 ****************************************************************************/
38
39 return a;
40 }
41
42 static_assert(
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."
45 );
46 #endif // #ifndef _MSC_VER
47
48 template <class T>
49 constexpr auto tie_as_tuple(T& val) noexcept {
50 static_assert(
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."
53 );
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{});
56 }
57
58 template <class T, class F, std::size_t... I>
59 void for_each_field_dispatcher(T& t, F&& f, std::index_sequence<I...>) {
60 static_assert(
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."
63 );
64 std::forward<F>(f)(
65 detail::tie_as_tuple(t)
66 );
67 }
68
69 }}} // namespace boost::pfr::detail
70
71 #endif // BOOST_PFR_DETAIL_CORE17_HPP