Bug 1153295 - Add mozilla::AddRvalueReference. r=nfroyd

This commit is contained in:
Gerald Squelart 2015-04-27 18:07:00 -04:00
Родитель 913d8b5a1a
Коммит 173514b341
2 изменённых файлов: 55 добавлений и 2 удалений

Просмотреть файл

@ -755,8 +755,8 @@ struct AddLvalueReferenceHelper<T, TIsNotVoid>
/**
* AddLvalueReference adds an lvalue & reference to T if one isn't already
* present. (Note: adding an lvalue reference to an rvalue && reference in
* essence replaces the && with a &&, per C+11 reference collapsing rules. For
* present. (Note: adding an lvalue reference to an rvalue && reference in
* essence replaces the && with a &&, per C+11 reference collapsing rules. For
* example, int&& would become int&.)
*
* The final computed type will only *not* be an lvalue reference if T is void.
@ -772,6 +772,45 @@ struct AddLvalueReference
: detail::AddLvalueReferenceHelper<T>
{};
namespace detail {
template<typename T, Voidness V = IsVoid<T>::value ? TIsVoid : TIsNotVoid>
struct AddRvalueReferenceHelper;
template<typename T>
struct AddRvalueReferenceHelper<T, TIsVoid>
{
typedef void Type;
};
template<typename T>
struct AddRvalueReferenceHelper<T, TIsNotVoid>
{
typedef T&& Type;
};
} // namespace detail
/**
* AddRvalueReference adds an rvalue && reference to T if one isn't already
* present. (Note: adding an rvalue reference to an lvalue & reference in
* essence keeps the &, per C+11 reference collapsing rules. For example,
* int& would remain int&.)
*
* The final computed type will only *not* be a reference if T is void.
*
* mozilla::AddRvalueReference<int>::Type is int&&;
* mozilla::AddRvalueRference<volatile int&>::Type is volatile int&;
* mozilla::AddRvalueRference<const int&&>::Type is const int&&;
* mozilla::AddRvalueReference<void*>::Type is void*&&;
* mozilla::AddRvalueReference<void>::Type is void;
* mozilla::AddRvalueReference<struct S&>::Type is struct S&.
*/
template<typename T>
struct AddRvalueReference
: detail::AddRvalueReferenceHelper<T>
{};
/* 20.9.7.3 Sign modifications [meta.trans.sign] */
template<bool B, typename T = void>

Просмотреть файл

@ -8,6 +8,7 @@
#include "mozilla/TypeTraits.h"
using mozilla::AddLvalueReference;
using mozilla::AddRvalueReference;
using mozilla::IsArray;
using mozilla::IsBaseOf;
using mozilla::IsClass;
@ -371,6 +372,19 @@ static_assert(IsSame<AddLvalueReference<void>::Type, void>::value,
static_assert(IsSame<AddLvalueReference<struct S1&&>::Type, struct S1&>::value,
"not reference-collapsing struct S1&& & to struct S1& correctly");
static_assert(IsSame<AddRvalueReference<int>::Type, int&&>::value,
"not adding && to int correctly");
static_assert(IsSame<AddRvalueReference<volatile int&>::Type, volatile int&>::value,
"not adding && to volatile int& correctly");
static_assert(IsSame<AddRvalueReference<const int&&>::Type, const int&&>::value,
"not adding && to volatile int& correctly");
static_assert(IsSame<AddRvalueReference<void*>::Type, void*&&>::value,
"not adding && to void* correctly");
static_assert(IsSame<AddRvalueReference<void>::Type, void>::value,
"void shouldn't be transformed by AddRvalueReference");
static_assert(IsSame<AddRvalueReference<struct S1&>::Type, struct S1&>::value,
"not reference-collapsing struct S1& && to struct S1& correctly");
static_assert(IsSame<MakeSigned<const unsigned char>::Type, const signed char>::value,
"const unsigned char won't signify correctly");
static_assert(IsSame<MakeSigned<volatile unsigned short>::Type, volatile signed short>::value,