possible_reflectable.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (c) 2022 Denis Mikhailov
  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. #ifndef BOOST_PFR_DETAIL_POSSIBLE_REFLECTABLE_HPP
  6. #define BOOST_PFR_DETAIL_POSSIBLE_REFLECTABLE_HPP
  7. #pragma once
  8. #include <boost/pfr/detail/config.hpp>
  9. #include <boost/pfr/traits_fwd.hpp>
  10. #if !defined(BOOST_PFR_INTERFACE_UNIT)
  11. #include <type_traits> // for std::is_aggregate
  12. #endif
  13. namespace boost { namespace pfr { namespace detail {
  14. ///////////////////// Returns false when the type exactly wasn't be reflectable
  15. template <class T, class WhatFor>
  16. constexpr decltype(is_reflectable<T, WhatFor>::value) possible_reflectable(long) noexcept {
  17. return is_reflectable<T, WhatFor>::value;
  18. }
  19. #if BOOST_PFR_ENABLE_IMPLICIT_REFLECTION
  20. template <class T, class WhatFor>
  21. constexpr bool possible_reflectable(int) noexcept {
  22. # if defined(__cpp_lib_is_aggregate)
  23. using type = std::remove_cv_t<T>;
  24. return std::is_aggregate<type>();
  25. # else
  26. return true;
  27. # endif
  28. }
  29. #else
  30. template <class T, class WhatFor>
  31. constexpr bool possible_reflectable(int) noexcept {
  32. // negative answer here won't change behaviour in PFR-dependent libraries(like Fusion)
  33. return false;
  34. }
  35. #endif
  36. }}} // namespace boost::pfr::detail
  37. #endif // BOOST_PFR_DETAIL_POSSIBLE_REFLECTABLE_HPP