static_rtti.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) 2018-2025 Jean-Louis Leroy
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // See accompanying file LICENSE_1_0.txt
  4. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_OPENMETHOD_POLICY_MINIMAL_RTTI_HPP
  6. #define BOOST_OPENMETHOD_POLICY_MINIMAL_RTTI_HPP
  7. #include <boost/openmethod/preamble.hpp>
  8. namespace boost::openmethod::policies {
  9. //! Minimal implementation of the `rtti` policy.
  10. //!
  11. //! `static_rtti` implements only the static parts of the `rtti` policy. It uses
  12. //! the addresses of a per-class static variables as a `type_id`. It categorizes
  13. //! all types as non-polymorphic. As a consequence, the `virtual_ptr`
  14. //! constructors that take a pointer or a reference to a polymorphic object are
  15. //! disabled. `virtual_ptr` must be constructed using @ref final_virtual_ptr (or
  16. //! its equivalents for smart pointers).
  17. //!
  18. //! @par Example
  19. //! TODO
  20. //! include::example$static_rtti.cpp[tag=all]
  21. struct static_rtti : rtti {
  22. //! A RttiFn metafunction.
  23. //!
  24. //! @tparam Registry The registry containing this policy.
  25. template<class Registry>
  26. struct fn : rtti::defaults {
  27. //! Always evaluates to `false`.
  28. //! @tparam Class A class.
  29. template<class Class>
  30. static constexpr bool is_polymorphic = false;
  31. //! Returns the @ref type_id of `Class`.
  32. //!
  33. //! @tparam Class A class.
  34. template<typename T>
  35. static auto static_type() -> type_id {
  36. static char id;
  37. return &id;
  38. }
  39. };
  40. };
  41. } // namespace boost::openmethod::policies
  42. #endif