type-traits.h 1.08 KB
Newer Older
1 2 3 4
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_BASE_TYPE_TRAITS_H_
#define V8_BASE_TYPE_TRAITS_H_
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

#include <type_traits>

namespace v8 {
namespace internal {

// Conjunction metafunction.
template <class... Args>
struct conjunction;

template <>
struct conjunction<> : std::true_type {};

template <class T>
struct conjunction<T> : T {};

template <class T, class... Args>
struct conjunction<T, Args...>
    : std::conditional<T::value, conjunction<Args...>, T>::type {};

// Disjunction metafunction.
template <class... Args>
struct disjunction;

template <>
struct disjunction<> : std::true_type {};

template <class T>
struct disjunction<T> : T {};

template <class T, class... Args>
struct disjunction<T, Args...>
    : std::conditional<T::value, T, disjunction<Args...>>::type {};

// Negation metafunction.
template <class T>
struct negation : std::integral_constant<bool, !T::value> {};

}  // namespace internal
}  // namespace v8

48
#endif  // V8_BASE_TYPE_TRAITS_H_