STL: extend type_traits to deal with member pointers

This commit is contained in:
Vito Gamberini
2024-06-28 23:07:07 -04:00
parent 73f368b3c1
commit e0f9d81f09
2 changed files with 34 additions and 0 deletions

View File

@@ -249,6 +249,14 @@ These are:
* ``cm::is_unique_ptr``:
Checks if a type is a ``std::unique_ptr`` type.
* ``cm::remove_member_pointer``
Produces the underlying type of a member-pointer type, ie, given ``T C::*``,
returns ``T``.
* ``cm::member_pointer_class``
Produces the class associated with a member-pointer type, ie, given
``T C::*``, returns ``C``.
CMake assumes the compiler supports ``#pragma once``. Use this for all
hand-written header files.

View File

@@ -82,4 +82,30 @@ using is_sequence_container =
!cm::is_associative_container<T>::value &&
!cm::is_unordered_associative_container<T>::value>;
template <typename T>
struct remove_member_pointer
{
typedef T type;
};
template <typename T, typename U>
struct remove_member_pointer<T U::*>
{
typedef T type;
};
template <typename T>
using remove_member_pointer_t = typename remove_member_pointer<T>::type;
template <typename T>
struct member_pointer_class
{
typedef T type;
};
template <typename T, typename U>
struct member_pointer_class<U T::*>
{
typedef T type;
};
template <typename T>
using member_pointer_class_t = typename member_pointer_class<T>::type;
} // namespace cm