Bug 1732219 - Add API for fetching the preview image. r=geckoview-reviewers,agi,mconley
[gecko.git] / mfbt / TypeTraits.h
blobde4c93cba0731997d8e5f5dde20be69ff8ab1378
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>
15 #include <utility>
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.
23 namespace mozilla {
25 /* 20.9.4 Unary type traits [meta.unary] */
27 /* 20.9.4.3 Type properties [meta.unary.prop] */
29 /**
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.
37 template <typename T>
38 struct IsPod : public std::false_type {};
40 template <>
41 struct IsPod<char> : std::true_type {};
42 template <>
43 struct IsPod<signed char> : std::true_type {};
44 template <>
45 struct IsPod<unsigned char> : std::true_type {};
46 template <>
47 struct IsPod<short> : std::true_type {};
48 template <>
49 struct IsPod<unsigned short> : std::true_type {};
50 template <>
51 struct IsPod<int> : std::true_type {};
52 template <>
53 struct IsPod<unsigned int> : std::true_type {};
54 template <>
55 struct IsPod<long> : std::true_type {};
56 template <>
57 struct IsPod<unsigned long> : std::true_type {};
58 template <>
59 struct IsPod<long long> : std::true_type {};
60 template <>
61 struct IsPod<unsigned long long> : std::true_type {};
62 template <>
63 struct IsPod<bool> : std::true_type {};
64 template <>
65 struct IsPod<float> : std::true_type {};
66 template <>
67 struct IsPod<double> : std::true_type {};
68 template <>
69 struct IsPod<wchar_t> : std::true_type {};
70 template <>
71 struct IsPod<char16_t> : std::true_type {};
72 template <typename T>
73 struct IsPod<T*> : std::true_type {};
75 namespace detail {
77 struct DoIsDestructibleImpl {
78 template <typename T, typename = decltype(std::declval<T&>().~T())>
79 static std::true_type test(int);
80 template <typename T>
81 static std::false_type test(...);
84 template <typename T>
85 struct IsDestructibleImpl : public DoIsDestructibleImpl {
86 typedef decltype(test<T>(0)) Type;
89 } // namespace detail
91 /**
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 */