1 //===- STLForwardCompat.h - Library features from future STLs ------C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file contains library features backported from future STL versions.
11 ///
12 /// These should be replaced with their STL counterparts as the C++ version LLVM
13 /// is compiled with is updated.
14 ///
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_ADT_STLFORWARDCOMPAT_H
18 #define LLVM_ADT_STLFORWARDCOMPAT_H
19 
20 #include <type_traits>
21 
22 namespace llvm {
23 
24 //===----------------------------------------------------------------------===//
25 //     Features from C++17
26 //===----------------------------------------------------------------------===//
27 
28 template <typename T>
29 struct negation // NOLINT(readability-identifier-naming)
30     : std::integral_constant<bool, !bool(T::value)> {};
31 
32 template <typename...>
33 struct conjunction // NOLINT(readability-identifier-naming)
34     : std::true_type {};
35 template <typename B1> struct conjunction<B1> : B1 {};
36 template <typename B1, typename... Bn>
37 struct conjunction<B1, Bn...>
38     : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
39 
40 template <typename...>
41 struct disjunction // NOLINT(readability-identifier-naming)
42     : std::false_type {};
43 template <typename B1> struct disjunction<B1> : B1 {};
44 template <typename B1, typename... Bn>
45 struct disjunction<B1, Bn...>
46     : std::conditional<bool(B1::value), B1, disjunction<Bn...>>::type {};
47 
48 struct in_place_t // NOLINT(readability-identifier-naming)
49 {
50   explicit in_place_t() = default;
51 };
52 /// \warning This must not be odr-used, as it cannot be made \c inline in C++14.
53 constexpr in_place_t in_place; // NOLINT(readability-identifier-naming)
54 
55 template <typename T>
56 struct in_place_type_t // NOLINT(readability-identifier-naming)
57 {
58   explicit in_place_type_t() = default;
59 };
60 
61 template <std::size_t I>
62 struct in_place_index_t // NOLINT(readability-identifier-naming)
63 {
64   explicit in_place_index_t() = default;
65 };
66 
67 //===----------------------------------------------------------------------===//
68 //     Features from C++20
69 //===----------------------------------------------------------------------===//
70 
71 template <typename T>
72 struct remove_cvref // NOLINT(readability-identifier-naming)
73 {
74   using type = std::remove_cv_t<std::remove_reference_t<T>>;
75 };
76 
77 template <typename T>
78 using remove_cvref_t // NOLINT(readability-identifier-naming)
79     = typename llvm::remove_cvref<T>::type;
80 
81 } // namespace llvm
82 
83 #endif // LLVM_ADT_STLFORWARDCOMPAT_H
84