Skip to content
Snippets Groups Projects
Commit 90df63ca authored by Oliver Sander's avatar Oliver Sander
Browse files

Implement is_pointer, is_lvalue_reference, remove_pointer

These are replacements for TypeTraits::isPointer, TypeTraits::isReference,
TypeTraits::PointeeType.  They reimplement what is available in the
C++11 standard library, and are expected to supersede the TypeTraits
class eventually.

Note: this patch does not pull in the corresponding stl implementation.
parent 30812ce9
Branches
Tags
No related merge requests found
......@@ -39,5 +39,34 @@ int main() {
assert( (Dune::is_same<int, Dune::TypeTraits<int>::ReferredType>::value) );
assert( (Dune::is_same<int, Dune::TypeTraits<int&>::ReferredType>::value) );
// Test is_pointer
assert( not Dune::is_pointer<int>::value );
assert( Dune::is_pointer<int*>::value );
assert( Dune::is_pointer<int**>::value );
assert( Dune::is_pointer<int(*)(int)>::value );
// Test is_reference
assert( not Dune::is_lvalue_reference<int>::value );
assert( Dune::is_lvalue_reference<int&>::value );
#if HAVE_RVALUE_REFERENCES
assert( not Dune::is_lvalue_reference<int&&>::value );
#endif
// Test remove_pointer
// Note: when the argument T is not a pointer, TypeTraits::PointeeType returns Dune::Empty,
// while Dune::remove_pointer (as std::remove_pointer), returns T itself
assert( (Dune::is_same<int, Dune::remove_pointer<int>::type>::value) );
assert( (Dune::is_same<int, Dune::remove_pointer<int*>::type>::value) );
assert( (Dune::is_same<int*, Dune::remove_pointer<int**>::type>::value) );
assert( (Dune::is_same<const int, Dune::remove_pointer<const int*>::type>::value) );
assert( (Dune::is_same<int, Dune::remove_pointer<int* const>::type>::value) );
// Test remove_reference
assert( (Dune::is_same<int, Dune::remove_reference<int>::type>::value) );
assert( (Dune::is_same<int, Dune::remove_reference<int&>::type>::value) );
#if HAVE_RVALUE_REFERENCES
assert( (Dune::is_same<int, Dune::remove_reference<int&&>::type>::value) );
#endif
return 0;
}
......@@ -32,6 +32,12 @@ namespace Dune
/**
* @brief General type traits class to check whether type is reference or
* pointer type
*
* \deprecated This class will be replaced by alternatives found in the C++11 stl.
* - Use is_pointer<T>::value instead of TypeTraits<T>::isPointer
* - Use is_lvalue_reference<T>::value instead of TypeTraits<T>::isReference
* - Use remove_pointer<T>::type instead of TypeTraits<T>::PointeeType
* - Use remove_reference<T>::type instead of TypeTraits<T>::ReferredType
*/
template <typename T>
class TypeTraits
......@@ -465,6 +471,53 @@ namespace Dune
typedef integral_constant<bool, false> false_type;
#endif // #else // #if HAVE_INTEGRAL_CONSTANT
template<typename>
struct __is_pointer_helper
: public false_type { };
template<typename T>
struct __is_pointer_helper<T*>
: public true_type { };
/// is_pointer
template<typename T>
struct is_pointer
: public integral_constant<bool, (__is_pointer_helper<T>::value)>
{ };
// Helper class for is_lvalue_reference
template<typename>
struct __is_lvalue_reference_helper
: public false_type { };
template<typename T>
struct __is_lvalue_reference_helper<T&>
: public true_type { };
/** \brief Determine whether a type is a lvalue reference type */
template<typename T>
struct is_lvalue_reference
: public integral_constant<bool, (__is_lvalue_reference_helper<T>::value)>
{ };
template<typename _Tp>
struct __remove_pointer_helper
{ typedef _Tp type; };
template<typename _Tp>
struct __remove_pointer_helper<_Tp*>
{ typedef _Tp type; };
/** \brief Return the type a pointer type points to
*
* \note When the argument T is not a pointer, TypeTraits::PointeeType returns Dune::Empty,
* while Dune::remove_pointer (as std::remove_pointer), returns T itself.
*/
template<typename _Tp>
struct remove_pointer
: public __remove_pointer_helper<typename remove_const<_Tp>::type >
{ };
/** @} */
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment