Bug 953296 - Implement mozilla::RemoveExtent. r=jcranmer

--HG--
extra : rebase_source : 97d4f055fc80074265bd5c8b1b0a565d8e994e7b
This commit is contained in:
Jeff Walden 2014-06-10 12:58:17 -07:00
parent 3be55730af
commit 4f1fa063ff
2 changed files with 37 additions and 0 deletions

View File

@ -846,6 +846,33 @@ struct MakeUnsigned
/* 20.9.7.4 Array modifications [meta.trans.arr] */
/**
* RemoveExtent produces either the type of the elements of the array T, or T
* itself.
*
* mozilla::RemoveExtent<int>::Type is int;
* mozilla::RemoveExtent<const int[]>::Type is const int;
* mozilla::RemoveExtent<volatile int[5]>::Type is volatile int;
* mozilla::RemoveExtent<long[][17]>::Type is long[17].
*/
template<typename T>
struct RemoveExtent
{
typedef T Type;
};
template<typename T>
struct RemoveExtent<T[]>
{
typedef T Type;
};
template<typename T, decltype(sizeof(1)) N>
struct RemoveExtent<T[N]>
{
typedef T Type;
};
/* 20.9.7.5 Pointer modifications [meta.trans.ptr] */
/* 20.9.7.6 Other transformations [meta.trans.other] */

View File

@ -19,6 +19,7 @@ using mozilla::IsSigned;
using mozilla::IsUnsigned;
using mozilla::MakeSigned;
using mozilla::MakeUnsigned;
using mozilla::RemoveExtent;
static_assert(!IsArray<bool>::value, "bool not an array");
static_assert(IsArray<bool[]>::value, "bool[] is an array");
@ -292,6 +293,15 @@ static_assert(IsSame<MakeUnsigned<volatile char>::Type, volatile unsigned char>:
static_assert(IsSame<MakeUnsigned<const char>::Type, const unsigned char>::value,
"const char won't unsignify correctly");
static_assert(IsSame<RemoveExtent<int>::Type, int>::value,
"removing extent from non-array must return the non-array");
static_assert(IsSame<RemoveExtent<const int[]>::Type, const int>::value,
"removing extent from unknown-bound array must return element type");
static_assert(IsSame<RemoveExtent<volatile int[5]>::Type, volatile int>::value,
"removing extent from known-bound array must return element type");
static_assert(IsSame<RemoveExtent<long[][17]>::Type, long[17]>::value,
"removing extent from multidimensional array must return element type");
/*
* Android's broken [u]intptr_t inttype macros are broken because its PRI*PTR
* macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t)