diff options
Diffstat (limited to 'Utilities/std/cmext/memory')
-rw-r--r-- | Utilities/std/cmext/memory | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Utilities/std/cmext/memory b/Utilities/std/cmext/memory new file mode 100644 index 0000000..540a3de --- /dev/null +++ b/Utilities/std/cmext/memory @@ -0,0 +1,32 @@ +// -*-c++-*- +// vim: set ft=cpp: + +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmext_memory +#define cmext_memory + +#include <cm/type_traits> + +namespace cm { + +template <typename T, typename O, + cm::enable_if_t< + std::is_pointer<cm::invoke_result_t<decltype(&O::get), O>>::value, + int> = 0> +T& static_reference_cast(O& item) +{ + return *(static_cast<T*>(item.get())); +} +template <typename T, typename O, + cm::enable_if_t< + std::is_pointer<cm::invoke_result_t<decltype(&O::get), O>>::value, + int> = 0> +T& dynamic_reference_cast(O& item) +{ + return *(dynamic_cast<T*>(item.get())); +} + +} // namespace cm + +#endif |