fake_object.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2023 Bela Schaum, X-Ryl669, 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. // Initial implementation by Bela Schaum, https://github.com/schaumb
  6. // The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669
  7. //
  8. #ifndef BHO_PFR_DETAIL_FAKE_OBJECT_HPP
  9. #define BHO_PFR_DETAIL_FAKE_OBJECT_HPP
  10. #pragma once
  11. #include <asio2/bho/pfr/detail/config.hpp>
  12. namespace bho { namespace pfr { namespace detail {
  13. // This variable serves as a compile-time assert. If you see any error here, then
  14. // you're probably using `bho::pfr::get_name()` or `bho::pfr::names_as_array()` with a non-external linkage type.
  15. template <class T>
  16. extern const T passed_type_has_no_external_linkage;
  17. // For returning non default constructible types, it's exclusively used in member name retrieval.
  18. //
  19. // Neither std::declval nor bho::pfr::detail::unsafe_declval are usable there.
  20. // Limitation - T should have external linkage.
  21. template <class T>
  22. constexpr const T& fake_object() noexcept {
  23. return passed_type_has_no_external_linkage<T>;
  24. }
  25. }}} // namespace bho::pfr::detail
  26. #endif // BHO_PFR_DETAIL_FAKE_OBJECT_HPP