summaryrefslogtreecommitdiffstats
path: root/Utilities
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2019-11-18 18:15:49 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2019-11-27 15:03:04 (GMT)
commitfc3b4caa2e6a1970c75830445ef4aa7d03c5a533 (patch)
tree83e8eef4e853baab91218bf49120f04b342b8d96 /Utilities
parent7046a5219893436cbe19b6973ac13fb489199601 (diff)
downloadCMake-fc3b4caa2e6a1970c75830445ef4aa7d03c5a533.zip
CMake-fc3b4caa2e6a1970c75830445ef4aa7d03c5a533.tar.gz
CMake-fc3b4caa2e6a1970c75830445ef4aa7d03c5a533.tar.bz2
Memory management: cast functions for managed pointers
Diffstat (limited to 'Utilities')
-rw-r--r--Utilities/std/.gitattributes1
-rw-r--r--Utilities/std/cm/type_traits46
-rw-r--r--Utilities/std/cmext/memory32
3 files changed, 79 insertions, 0 deletions
diff --git a/Utilities/std/.gitattributes b/Utilities/std/.gitattributes
index cd20549..789a754 100644
--- a/Utilities/std/.gitattributes
+++ b/Utilities/std/.gitattributes
@@ -1 +1,2 @@
cm/* our-c-style
+cmext/* our-c-style
diff --git a/Utilities/std/cm/type_traits b/Utilities/std/cm/type_traits
new file mode 100644
index 0000000..6d7a2c0
--- /dev/null
+++ b/Utilities/std/cm/type_traits
@@ -0,0 +1,46 @@
+// -*-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 cm_type_traits
+#define cm_type_traits
+
+#include <type_traits> // IWYU pragma: export
+
+namespace cm {
+
+#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
+
+// Miscellaneous transformations
+template <bool B, typename T = void>
+using enable_if_t = std::enable_if_t<B, T>;
+
+#else
+
+// Miscellaneous transformations
+template <bool B, typename T = void>
+using enable_if_t = typename std::enable_if<B, T>::type;
+
+#endif
+
+#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703)
+
+// Miscellaneous transformations
+using std::invoke_result;
+using std::invoke_result_t;
+
+#else
+
+// Miscellaneous transformations
+template <typename F, typename... ArgTypes>
+using invoke_result = std::result_of<F(ArgTypes...)>;
+
+template <class F, typename... ArgTypes>
+using invoke_result_t = typename invoke_result<F, ArgTypes...>::type;
+
+#endif
+
+} // namespace cm
+
+#endif
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