Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: base/type_traits.h

Issue 2944523002: Improving flat containers interface. (Closed)
Patch Set: Removing redundant tests. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« base/containers/flat_tree.h ('K') | « base/functional_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_TYPE_TRAITS_H_
6 #define BASE_TYPE_TRAITS_H_
7
8 #include <type_traits>
9
10 namespace base {
11
12 // C++14 ---------------------------------------------------------------------
13
14 template <bool condition, typename T = void>
15 using enable_if_t = typename std::enable_if<condition, T>::type;
16
17 template <bool condition, typename T, typename U>
18 using condtional_t = typename std::conditional<condition, T, U>::type;
19
20 // C++17 ----------------------------------------------------------------------
21
22 // Detection idiom. We use constexpr function is_detected_c() instead of a
23 // variable template.
24
25 template <typename...>
26 using void_t = void;
27
28 struct nonesuch {
29 nonesuch() = delete;
30 ~nonesuch() = delete;
31 nonesuch(nonesuch const&) = delete;
32 void operator=(nonesuch const&) = delete;
33 };
34
35 namespace internal {
36
37 template <typename Default,
38 typename AlwaysVoid,
39 template <typename...> class Op,
40 typename... Args>
41 struct detector {
42 using value_t = std::false_type;
43 using type = Default;
44 };
45
46 template <typename Default, template <typename...> class Op, typename... Args>
47 struct detector<Default, void_t<Op<Args...>>, Op, Args...> {
48 using value_t = std::true_type;
49 using type = Op<Args...>;
50 };
51
52 } // namespace internal
53
54 template <template <class...> class Op, typename... Args>
55 using is_detected =
56 typename internal::detector<nonesuch, void, Op, Args...>::value_t;
57
58 template <typename Default, template <typename...> class Op, typename... Args>
59 using detected_or = internal::detector<Default, void, Op, Args...>;
60
61 template <template <typename...> class Op, typename... Args>
62 constexpr bool is_detected_c() {
63 return is_detected<Op, Args...>::value;
64 }
65
66 } // namespace base
67
68 #endif // BASE_TYPE_TRAITS_H_
OLDNEW
« base/containers/flat_tree.h ('K') | « base/functional_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698