зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1163328 - Add an And<...> class to TemplateLib.h which performs logical and on a variadic number of booleans known at compile time. r=froydnj
--HG-- extra : source : 1869b74e535c7ef43ac3e21793847f82f2b468de
This commit is contained in:
Родитель
5b4c1f3bf9
Коммит
5d8adc885c
|
@ -20,6 +20,8 @@
|
|||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "mozilla/TypeTraits.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace tl {
|
||||
|
@ -105,6 +107,25 @@ struct MulOverflowMask
|
|||
template<> struct MulOverflowMask<0> { /* Error */ };
|
||||
template<> struct MulOverflowMask<1> { static const size_t value = 0; };
|
||||
|
||||
/**
|
||||
* And<bool...> computes the logical 'and' of its argument booleans.
|
||||
*
|
||||
* Examples:
|
||||
* mozilla::t1::And<true, true>::value is true.
|
||||
* mozilla::t1::And<true, false>::value is false.
|
||||
* mozilla::t1::And<>::value is true.
|
||||
*/
|
||||
|
||||
template<bool...>
|
||||
struct And;
|
||||
|
||||
template<>
|
||||
struct And<> : public TrueType { };
|
||||
|
||||
template<bool C1, bool... Cn>
|
||||
struct And<C1, Cn...>
|
||||
: public Conditional<C1, And<Cn...>, FalseType>::Type { };
|
||||
|
||||
} // namespace tl
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/TemplateLib.h"
|
||||
|
||||
using mozilla::tl::And;
|
||||
|
||||
static_assert(And<>::value == true,
|
||||
"And<>::value should be true");
|
||||
static_assert(And<true>::value == true,
|
||||
"And<true>::value should be true");
|
||||
static_assert(And<false>::value == false,
|
||||
"And<false>::value should be false");
|
||||
static_assert(And<false, true>::value == false,
|
||||
"And<false, true>::value should be false");
|
||||
static_assert(And<false, false>::value == false,
|
||||
"And<false, false>::value should be false");
|
||||
static_assert(And<true, false>::value == false,
|
||||
"And<true, false>::value should be false");
|
||||
static_assert(And<true, true>::value == true,
|
||||
"And<true, true>::value should be true");
|
||||
static_assert(And<true, true, true>::value == true,
|
||||
"And<true, true, true>::value should be true");
|
||||
static_assert(And<true, false, true>::value == false,
|
||||
"And<true, false, true>::value should be false");
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
// Nothing to do here.
|
||||
return 0;
|
||||
}
|
|
@ -28,6 +28,7 @@ CppUnitTests([
|
|||
'TestSegmentedVector',
|
||||
'TestSHA1',
|
||||
'TestSplayTree',
|
||||
'TestTemplateLib',
|
||||
'TestTypedEnum',
|
||||
'TestTypeTraits',
|
||||
'TestUniquePtr',
|
||||
|
|
Загрузка…
Ссылка в новой задаче