Skip to content

Commit

Permalink
Add RemovePointer type trait utility
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Banderali <leonardo2718@protonmail.com>
  • Loading branch information
Leonardo2718 committed Dec 17, 2018
1 parent 2c6df63 commit 6bc609c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fvtest/coretest/TestTypeTraits.cpp
Expand Up @@ -98,6 +98,17 @@ TEST(TestTypeTraits, RemoveCvRef)
// TODO: EXPECT_TRUE((IsSame<int, RemoveCvRef<int&&>::Type>::VALUE));
}

TEST(TestTypeTraits, RemovePointer)
{
EXPECT_TRUE((IsSame<int, RemovePointer<int>::Type>::VALUE));
EXPECT_TRUE((IsSame<int, RemovePointer<int*>::Type>::VALUE));
EXPECT_TRUE((IsSame<int, RemovePointer<int* const>::Type>::VALUE));
EXPECT_TRUE((IsSame<int, RemovePointer<int* volatile>::Type>::VALUE));
EXPECT_TRUE((IsSame<int, RemovePointer<int* const volatile>::Type>::VALUE));
EXPECT_TRUE((IsSame<const volatile int, RemovePointer<const volatile int * const volatile>::Type>::VALUE));
EXPECT_TRUE((IsSame<int*&, RemovePointer<int*&>::Type>::VALUE));
}

TEST(TestTypeTraits, IsReference)
{
EXPECT_FALSE((IsReference<int>::VALUE));
Expand Down
11 changes: 11 additions & 0 deletions include_core/OMR/TypeTraits.hpp
Expand Up @@ -98,6 +98,17 @@ struct RemoveCvRef : RemoveCv<typename RemoveReference<T>::Type> {};
// template <typename T>
// struct RemoveCvRef<T&&> : RemoveCvRef<T> {};

/// Remove one layer of non-cv-qualified pointers
template <typename T>
struct RemoveNonCvPointer : TypeAlias<T> {};

template <typename T>
struct RemoveNonCvPointer<T*> : TypeAlias<T> {};

/// Remove one layer of possibly cv-qualified pointers
template <typename T>
struct RemovePointer : RemoveNonCvPointer<typename RemoveCv<T>::Type> {};

///
/// Type reflection: statically query types
///
Expand Down

0 comments on commit 6bc609c

Please sign in to comment.