Bug 953296 - Implement mozilla::IsArray. r=froydnj

--HG--
extra : rebase_source : 3eb6fff774f28c39374f1e7c148f472d95e538c0
This commit is contained in:
Jeff Walden 2013-12-30 01:07:32 -06:00
parent e8f647be21
commit 27874984d9
2 changed files with 32 additions and 0 deletions

View File

@ -9,6 +9,8 @@
#ifndef mozilla_TypeTraits_h
#define mozilla_TypeTraits_h
#include "mozilla/Types.h"
/*
* These traits are approximate copies of the traits and semantics from C++11's
* <type_traits> header. Don't add traits not in that header! When all
@ -114,6 +116,31 @@ struct IsFloatingPoint
: detail::IsFloatingPointHelper<typename RemoveCV<T>::Type>
{};
namespace detail {
template<typename T>
struct IsArrayHelper : FalseType {};
template<typename T, decltype(sizeof(1)) N>
struct IsArrayHelper<T[N]> : TrueType {};
template<typename T>
struct IsArrayHelper<T[]> : TrueType {};
} // namespace detail
/**
* IsArray determines whether a type is an array type, of known or unknown
* length.
*
* mozilla::IsArray<int>::value is false;
* mozilla::IsArray<int[]>::value is true;
* mozilla::IsArray<int[5]>::value is true.
*/
template<typename T>
struct IsArray : detail::IsArrayHelper<typename RemoveCV<T>::Type>
{};
/**
* IsPointer determines whether a type is a pointer type (but not a pointer-to-
* member type).

View File

@ -6,6 +6,7 @@
#include "mozilla/Assertions.h"
#include "mozilla/TypeTraits.h"
using mozilla::IsArray;
using mozilla::IsBaseOf;
using mozilla::IsClass;
using mozilla::IsConvertible;
@ -19,6 +20,10 @@ using mozilla::IsUnsigned;
using mozilla::MakeSigned;
using mozilla::MakeUnsigned;
static_assert(!IsArray<bool>::value, "bool not an array");
static_assert(IsArray<bool[]>::value, "bool[] is an array");
static_assert(IsArray<bool[5]>::value, "bool[5] is an array");
static_assert(!IsLvalueReference<bool>::value, "bool not an lvalue reference");
static_assert(!IsLvalueReference<bool*>::value, "bool* not an lvalue reference");
static_assert(IsLvalueReference<bool&>::value, "bool& is an lvalue reference");