template <typename T> bool any_isa(const Any &Value) {
if (!Value.Storage)
return false;
- return Value.Storage->id() ==
- &Any::TypeId<std::remove_cv_t<std::remove_reference_t<T>>>::Id;
+ return Value.Storage->id() == &Any::TypeId<remove_cvref_t<T>>::Id;
}
template <class T> T any_cast(const Any &Value) {
- return static_cast<T>(
- *any_cast<std::remove_cv_t<std::remove_reference_t<T>>>(&Value));
+ return static_cast<T>(*any_cast<remove_cvref_t<T>>(&Value));
}
template <class T> T any_cast(Any &Value) {
- return static_cast<T>(
- *any_cast<std::remove_cv_t<std::remove_reference_t<T>>>(&Value));
+ return static_cast<T>(*any_cast<remove_cvref_t<T>>(&Value));
}
template <class T> T any_cast(Any &&Value) {
- return static_cast<T>(std::move(
- *any_cast<std::remove_cv_t<std::remove_reference_t<T>>>(&Value)));
+ return static_cast<T>(std::move(*any_cast<remove_cvref_t<T>>(&Value)));
}
template <class T> const T *any_cast(const Any *Value) {
- using U = std::remove_cv_t<std::remove_reference_t<T>>;
+ using U = remove_cvref_t<T>;
assert(Value && any_isa<T>(*Value) && "Bad any cast!");
if (!Value || !any_isa<U>(*Value))
return nullptr;
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/Support/MemAlloc.h"
#include "llvm/Support/type_traits.h"
#include <memory>
std::enable_if_t<llvm::is_trivially_move_constructible<T>::value &&
std::is_trivially_destructible<T>::value>;
template <typename CallableT, typename ThisT>
-using EnableUnlessSameType = std::enable_if_t<!std::is_same<
- std::remove_cv_t<std::remove_reference_t<CallableT>>, ThisT>::value>;
+using EnableUnlessSameType =
+ std::enable_if_t<!std::is_same<remove_cvref_t<CallableT>, ThisT>::value>;
template <typename CallableT, typename Ret, typename... Params>
using EnableIfCallable =
std::enable_if_t<std::is_void<Ret>::value ||
function_ref(
Callable &&callable,
// This is not the copy-constructor.
- std::enable_if_t<
- !std::is_same<std::remove_cv_t<std::remove_reference_t<Callable>>,
- function_ref>::value> * = nullptr,
+ std::enable_if_t<!std::is_same<remove_cvref_t<Callable>,
+ function_ref>::value> * = nullptr,
// Functor must be callable and return a suitable type.
std::enable_if_t<std::is_void<Ret>::value ||
std::is_convertible<decltype(std::declval<Callable>()(
struct disjunction<B1, Bn...>
: std::conditional<bool(B1::value), B1, disjunction<Bn...>>::type {};
+//===----------------------------------------------------------------------===//
+// Features from C++20
+//===----------------------------------------------------------------------===//
+
+template <typename T>
+struct remove_cvref // NOLINT(readability-identifier-naming)
+{
+ using type = std::remove_cv_t<std::remove_reference_t<T>>;
+};
+
+template <typename T>
+using remove_cvref_t // NOLINT(readability-identifier-naming)
+ = typename llvm::remove_cvref<T>::type;
+
} // namespace llvm
#endif // LLVM_ADT_STLFORWARDCOMPAT_H
std::true_type>::value));
}
+template <typename T>
+class STLForwardCompatRemoveCVRefTest : public ::testing::Test {};
+
+using STLForwardCompatRemoveCVRefTestTypes = ::testing::Types<
+ // clang-format off
+ std::pair<int, int>,
+ std::pair<int &, int>,
+ std::pair<const int, int>,
+ std::pair<volatile int, int>,
+ std::pair<const volatile int &, int>,
+ std::pair<int *, int *>,
+ std::pair<int *const, int *>,
+ std::pair<const int *, const int *>,
+ std::pair<int *&, int *>
+ // clang-format on
+ >;
+
+TYPED_TEST_CASE(STLForwardCompatRemoveCVRefTest,
+ STLForwardCompatRemoveCVRefTestTypes);
+
+TYPED_TEST(STLForwardCompatRemoveCVRefTest, RemoveCVRef) {
+ using From = typename TypeParam::first_type;
+ using To = typename TypeParam::second_type;
+ EXPECT_TRUE(
+ (std::is_same<typename llvm::remove_cvref<From>::type, To>::value));
+}
+
+TYPED_TEST(STLForwardCompatRemoveCVRefTest, RemoveCVRefT) {
+ using From = typename TypeParam::first_type;
+ EXPECT_TRUE((std::is_same<typename llvm::remove_cvref<From>::type,
+ llvm::remove_cvref_t<From>>::value));
+}
+
} // namespace