1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* Template-based metaprogramming and type-testing facilities. */
9 #ifndef mozilla_TypeTraits_h
10 #define mozilla_TypeTraits_h
12 #include "mozilla/Types.h"
14 #include <type_traits>
18 * These traits are approximate copies of the traits and semantics from C++11's
19 * <type_traits> header. Don't add traits not in that header! When all
20 * platforms provide that header, we can convert all users and remove this one.
25 /* 20.9.4 Unary type traits [meta.unary] */
27 /* 20.9.4.3 Type properties [meta.unary.prop] */
30 * Traits class for identifying POD types. Until C++11 there's no automatic
31 * way to detect PODs, so for the moment this is done manually. Users may
32 * define specializations of this class that inherit from std::true_type and
33 * std::false_type (or equivalently std::integral_constant<bool, true or
34 * false>, or conveniently from mozilla::IsPod for composite types) as needed to
35 * ensure correct IsPod behavior.
38 struct IsPod
: public std::false_type
{};
41 struct IsPod
<char> : std::true_type
{};
43 struct IsPod
<signed char> : std::true_type
{};
45 struct IsPod
<unsigned char> : std::true_type
{};
47 struct IsPod
<short> : std::true_type
{};
49 struct IsPod
<unsigned short> : std::true_type
{};
51 struct IsPod
<int> : std::true_type
{};
53 struct IsPod
<unsigned int> : std::true_type
{};
55 struct IsPod
<long> : std::true_type
{};
57 struct IsPod
<unsigned long> : std::true_type
{};
59 struct IsPod
<long long> : std::true_type
{};
61 struct IsPod
<unsigned long long> : std::true_type
{};
63 struct IsPod
<bool> : std::true_type
{};
65 struct IsPod
<float> : std::true_type
{};
67 struct IsPod
<double> : std::true_type
{};
69 struct IsPod
<wchar_t> : std::true_type
{};
71 struct IsPod
<char16_t
> : std::true_type
{};
73 struct IsPod
<T
*> : std::true_type
{};
77 struct DoIsDestructibleImpl
{
78 template <typename T
, typename
= decltype(std::declval
<T
&>().~T())>
79 static std::true_type
test(int);
81 static std::false_type
test(...);
85 struct IsDestructibleImpl
: public DoIsDestructibleImpl
{
86 typedef decltype(test
<T
>(0)) Type
;
92 * IsDestructible determines whether a type has a public destructor.
94 * struct S0 {}; // Implicit default destructor.
95 * struct S1 { ~S1(); };
96 * class C2 { ~C2(); }; // private destructor.
98 * mozilla::IsDestructible<S0>::value is true;
99 * mozilla::IsDestructible<S1>::value is true;
100 * mozilla::IsDestructible<C2>::value is false.
102 template <typename T
>
103 struct IsDestructible
: public detail::IsDestructibleImpl
<T
>::Type
{};
105 } /* namespace mozilla */
107 #endif /* mozilla_TypeTraits_h */