Implement more of P0006; Type Traits Variable Templates.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@254283 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2015-11-30 04:30:02 +00:00
parent 14ba0ad689
commit a3e7f528a2
7 changed files with 93 additions and 2 deletions

View File

@@ -1079,6 +1079,11 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY rank<_Tp[]>
template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY rank<_Tp[_Np]>
: public integral_constant<size_t, rank<_Tp>::value + 1> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp> _LIBCPP_CONSTEXPR bool rank_v
= rank<_Tp>::value;
#endif
// extent
template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TYPE_VIS_ONLY extent
@@ -1092,6 +1097,11 @@ template <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[_Np], 0
template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[_Np], _Ip>
: public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp, unsigned _Ip = 0> _LIBCPP_CONSTEXPR bool extent_v
= extent<_Tp, _Ip>::value;
#endif
// remove_extent
template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_extent
@@ -1218,6 +1228,11 @@ struct _LIBCPP_TYPE_VIS_ONLY is_base_of
#endif // _LIBCPP_HAS_IS_BASE_OF
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Bp, class _Dp> _LIBCPP_CONSTEXPR bool is_base_of_v
= is_base_of<_Bp, _Dp>::value;
#endif
// is_convertible
#if __has_feature(is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
@@ -1345,6 +1360,11 @@ template <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY is_convertible
#endif // __has_feature(is_convertible_to)
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _From, class _To> _LIBCPP_CONSTEXPR bool is_convertible_v
= is_convertible<_From, _To>::value;
#endif
// is_empty
#if __has_feature(is_empty) || (_GNUC_VER >= 407)
@@ -1430,6 +1450,11 @@ template <class _Tp> _LIBCPP_CONSTEXPR bool has_virtual_destructor_v
template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY alignment_of
: public integral_constant<size_t, __alignof__(_Tp)> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp> _LIBCPP_CONSTEXPR bool alignment_of_v
= alignment_of<_Tp>::value;
#endif
// aligned_storage
template <class _Hp, class _Tp>

View File

@@ -13,6 +13,8 @@
#include <type_traits>
#include "test_macros.h"
template <class T, class U>
void test_is_base_of()
{
@@ -20,6 +22,12 @@ void test_is_base_of()
static_assert((std::is_base_of<const T, U>::value), "");
static_assert((std::is_base_of<T, const U>::value), "");
static_assert((std::is_base_of<const T, const U>::value), "");
#if TEST_STD_VERS > 14
static_assert((std::is_base_of_v<T, U>), "");
static_assert((std::is_base_of_v<const T, U>), "");
static_assert((std::is_base_of_v<T, const U>), "");
static_assert((std::is_base_of_v<const T, const U>), "");
#endif
}
template <class T, class U>

View File

@@ -13,6 +13,8 @@
#include <type_traits>
#include "test_macros.h"
template <class T, class U>
void test_is_convertible()
{
@@ -20,6 +22,12 @@ void test_is_convertible()
static_assert((std::is_convertible<const T, U>::value), "");
static_assert((std::is_convertible<T, const U>::value), "");
static_assert((std::is_convertible<const T, const U>::value), "");
#if TEST_STD_VERS > 14
static_assert((std::is_convertible_v<T, U>), "");
static_assert((std::is_convertible_v<const T, U>), "");
static_assert((std::is_convertible_v<T, const U>), "");
static_assert((std::is_convertible_v<const T, const U>), "");
#endif
}
template <class T, class U>
@@ -29,6 +37,12 @@ void test_is_not_convertible()
static_assert((!std::is_convertible<const T, U>::value), "");
static_assert((!std::is_convertible<T, const U>::value), "");
static_assert((!std::is_convertible<const T, const U>::value), "");
#if TEST_STD_VERS > 14
static_assert((!std::is_convertible_v<T, U>), "");
static_assert((!std::is_convertible_v<const T, U>), "");
static_assert((!std::is_convertible_v<T, const U>), "");
static_assert((!std::is_convertible_v<const T, const U>), "");
#endif
}
typedef void Function();

View File

@@ -13,13 +13,21 @@
#include <type_traits>
#include "test_macros.h"
template <class T, class U>
void test_is_same()
{
static_assert((std::is_same<T, U>::value), "");
static_assert(( std::is_same<T, U>::value), "");
static_assert((!std::is_same<const T, U>::value), "");
static_assert((!std::is_same<T, const U>::value), "");
static_assert((std::is_same<const T, const U>::value), "");
static_assert(( std::is_same<const T, const U>::value), "");
#if TEST_STD_VERS > 14
static_assert(( std::is_same_v<T, U>), "");
static_assert((!std::is_same_v<const T, U>), "");
static_assert((!std::is_same_v<T, const U>), "");
static_assert(( std::is_same_v<const T, const U>), "");
#endif
}
template <class T, class U>
@@ -29,6 +37,12 @@ void test_is_same_ref()
static_assert((std::is_same<const T, U>::value), "");
static_assert((std::is_same<T, const U>::value), "");
static_assert((std::is_same<const T, const U>::value), "");
#if TEST_STD_VERS > 14
static_assert((std::is_same_v<T, U>), "");
static_assert((std::is_same_v<const T, U>), "");
static_assert((std::is_same_v<T, const U>), "");
static_assert((std::is_same_v<const T, const U>), "");
#endif
}
template <class T, class U>

View File

@@ -14,6 +14,8 @@
#include <type_traits>
#include <cstdint>
#include "test_macros.h"
template <class T, unsigned A>
void test_alignment_of()
{
@@ -21,6 +23,12 @@ void test_alignment_of()
static_assert( std::alignment_of<const T>::value == A, "");
static_assert( std::alignment_of<volatile T>::value == A, "");
static_assert( std::alignment_of<const volatile T>::value == A, "");
#if TEST_STD_VERS > 14
static_assert( std::alignment_of_v<T> == A, "");
static_assert( std::alignment_of_v<const T> == A, "");
static_assert( std::alignment_of_v<volatile T> == A, "");
static_assert( std::alignment_of_v<const volatile T> == A, "");
#endif
}
class Class

View File

@@ -13,6 +13,8 @@
#include <type_traits>
#include "test_macros.h"
template <class T, unsigned A>
void test_extent()
{
@@ -20,6 +22,12 @@ void test_extent()
static_assert((std::extent<const T>::value == A), "");
static_assert((std::extent<volatile T>::value == A), "");
static_assert((std::extent<const volatile T>::value == A), "");
#if TEST_STD_VERS > 14
static_assert((std::extent_v<T> == A), "");
static_assert((std::extent_v<const T> == A), "");
static_assert((std::extent_v<volatile T> == A), "");
static_assert((std::extent_v<const volatile T> == A), "");
#endif
}
template <class T, unsigned A>
@@ -29,6 +37,12 @@ void test_extent1()
static_assert((std::extent<const T, 1>::value == A), "");
static_assert((std::extent<volatile T, 1>::value == A), "");
static_assert((std::extent<const volatile T, 1>::value == A), "");
#if TEST_STD_VERS > 14
static_assert((std::extent_v<T, 1> == A), "");
static_assert((std::extent_v<const T, 1> == A), "");
static_assert((std::extent_v<volatile T, 1> == A), "");
static_assert((std::extent_v<const volatile T, 1> == A), "");
#endif
}
class Class

View File

@@ -13,6 +13,8 @@
#include <type_traits>
#include "test_macros.h"
template <class T, unsigned A>
void test_rank()
{
@@ -20,6 +22,12 @@ void test_rank()
static_assert( std::rank<const T>::value == A, "");
static_assert( std::rank<volatile T>::value == A, "");
static_assert( std::rank<const volatile T>::value == A, "");
#if TEST_STD_VERS > 14
static_assert( std::rank_v<T> == A, "");
static_assert( std::rank_v<const T> == A, "");
static_assert( std::rank_v<volatile T> == A, "");
static_assert( std::rank_v<const volatile T> == A, "");
#endif
}
class Class