File indexing completed on 2025-04-09 08:28:05
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_IMPL_PFR_HPP
0009 #define BOOST_MYSQL_IMPL_PFR_HPP
0010
0011 #pragma once
0012
0013 #include <boost/config.hpp>
0014
0015
0016
0017 #if BOOST_GCC >= 110000
0018 #pragma GCC diagnostic push
0019 #pragma GCC diagnostic ignored "-Wpragmas"
0020 #endif
0021
0022
0023 #if defined(BOOST_MSVC) && BOOST_MSVC < 1920
0024 #pragma warning(push)
0025 #pragma warning(disable : 4100)
0026 #endif
0027
0028 #include <boost/mysql/pfr.hpp>
0029 #include <boost/mysql/string_view.hpp>
0030
0031 #include <boost/mysql/detail/typing/row_traits.hpp>
0032
0033 #include <boost/pfr/core.hpp>
0034 #include <boost/pfr/core_name.hpp>
0035 #include <boost/pfr/traits.hpp>
0036
0037 #include <type_traits>
0038 #include <utility>
0039
0040 #if BOOST_PFR_CORE_NAME_ENABLED
0041 #include <array>
0042 #include <cstddef>
0043 #include <string_view>
0044 #endif
0045
0046 #if BOOST_GCC >= 110000
0047 #pragma GCC diagnostic pop
0048 #endif
0049
0050 namespace boost {
0051 namespace mysql {
0052 namespace detail {
0053
0054
0055 template <class T>
0056 constexpr bool is_pfr_reflectable() noexcept
0057 {
0058 return std::is_class<T>::value && !std::is_const<T>::value
0059
0060
0061 #if BOOST_PFR_ENABLE_IMPLICIT_REFLECTION
0062 && pfr::is_implicitly_reflectable_v<T, struct mysql_tag>
0063 #endif
0064 ;
0065 }
0066
0067 template <class T>
0068 using pfr_fields_t = decltype(pfr::structure_to_tuple(std::declval<const T&>()));
0069
0070 #if BOOST_PFR_CORE_NAME_ENABLED
0071
0072
0073 template <std::size_t N>
0074 constexpr std::array<string_view, N> to_name_table_storage(std::array<std::string_view, N> input) noexcept
0075 {
0076 std::array<string_view, N> res;
0077 for (std::size_t i = 0; i < N; ++i)
0078 res[i] = input[i];
0079 return res;
0080 }
0081
0082
0083 constexpr std::array<string_view, 0u> to_name_table_storage(std::array<std::nullptr_t, 0u>) noexcept
0084 {
0085 return {};
0086 }
0087
0088 template <class T>
0089 constexpr inline auto pfr_names_storage = to_name_table_storage(pfr::names_as_array<T>());
0090
0091 template <class T>
0092 class row_traits<pfr_by_name<T>, false>
0093 {
0094 static_assert(
0095 is_pfr_reflectable<T>(),
0096 "T needs to be a non-const object type that supports PFR reflection"
0097 );
0098
0099 public:
0100 using underlying_row_type = T;
0101 using field_types = pfr_fields_t<T>;
0102
0103 static constexpr name_table_t name_table() noexcept { return pfr_names_storage<T>; }
0104
0105 template <class F>
0106 static void for_each_member(T& to, F&& function)
0107 {
0108 pfr::for_each_field(to, std::forward<F>(function));
0109 }
0110 };
0111
0112 #endif
0113
0114 template <class T>
0115 class row_traits<pfr_by_position<T>, false>
0116 {
0117 static_assert(
0118 is_pfr_reflectable<T>(),
0119 "T needs to be a non-const object type that supports PFR reflection"
0120 );
0121
0122 public:
0123 using underlying_row_type = T;
0124 using field_types = pfr_fields_t<T>;
0125
0126 static constexpr name_table_t name_table() noexcept { return {}; }
0127
0128 template <class F>
0129 static void for_each_member(T& to, F&& function)
0130 {
0131 pfr::for_each_field(to, std::forward<F>(function));
0132 }
0133 };
0134
0135 }
0136 }
0137 }
0138
0139 #if defined(BOOST_MSVC) && BOOST_MSVC < 1920
0140 #pragma warning(pop)
0141 #endif
0142
0143 #endif