possible_reflectable.hpp 1.3 KB

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