core26.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (c) 2016-2025 Antony Polukhin
  2. // Copyright (c) 2025 Jean-Michaël Celerier
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. // boost-no-inspect
  7. #ifndef BOOST_PFR_DETAIL_CORE26_HPP
  8. #define BOOST_PFR_DETAIL_CORE26_HPP
  9. #pragma once
  10. #include <boost/pfr/detail/sequence_tuple.hpp>
  11. namespace boost::pfr::detail {
  12. template<class T>
  13. constexpr auto tie_as_tuple(T &val) noexcept {
  14. static_assert(!std::is_union<T>::value,
  15. "====================> Boost.PFR: For safety reasons it is forbidden to reflect "
  16. "unions. See `Reflection of unions` section in the docs for more info.");
  17. auto &&[... members] = std::forward<T>(val);
  18. return sequence_tuple::tuple<std::add_lvalue_reference_t<decltype(members)>...>{members...};
  19. }
  20. template <class T, class F, std::size_t... I>
  21. constexpr void for_each_field_dispatcher(T& t, F&& f, std::index_sequence<I...>) {
  22. static_assert(
  23. !std::is_union<T>::value,
  24. "====================> Boost.PFR: For safety reasons it is forbidden to reflect unions. See `Reflection of unions` section in the docs for more info."
  25. );
  26. std::forward<F>(f)(
  27. detail::tie_as_tuple(t)
  28. );
  29. }
  30. } // namespace boost::pfr::detail
  31. #endif