STLForwardCompat.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. // This file contains library features backported from future STL versions.
  10. //
  11. // These should be replaced with their STL counterparts as the C++ version LLVM
  12. // is compiled with is updated.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_ADT_STLFORWARDCOMPAT_H
  16. #define LLVM_ADT_STLFORWARDCOMPAT_H
  17. #include <type_traits>
  18. namespace llvm {
  19. //===----------------------------------------------------------------------===//
  20. // Features from C++17
  21. //===----------------------------------------------------------------------===//
  22. template <typename T>
  23. struct negation // NOLINT(readability-identifier-naming)
  24. : std::integral_constant<bool, !bool(T::value)> {};
  25. template <typename...>
  26. struct conjunction // NOLINT(readability-identifier-naming)
  27. : std::true_type {};
  28. template <typename B1> struct conjunction<B1> : B1 {};
  29. template <typename B1, typename... Bn>
  30. struct conjunction<B1, Bn...>
  31. : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
  32. template <typename...>
  33. struct disjunction // NOLINT(readability-identifier-naming)
  34. : std::false_type {};
  35. template <typename B1> struct disjunction<B1> : B1 {};
  36. template <typename B1, typename... Bn>
  37. struct disjunction<B1, Bn...>
  38. : std::conditional<bool(B1::value), B1, disjunction<Bn...>>::type {};
  39. struct in_place_t // NOLINT(readability-identifier-naming)
  40. {
  41. explicit in_place_t() = default;
  42. };
  43. /// \warning This must not be odr-used, as it cannot be made \c inline in C++14.
  44. constexpr in_place_t in_place; // NOLINT(readability-identifier-naming)
  45. template <typename T>
  46. struct in_place_type_t // NOLINT(readability-identifier-naming)
  47. {
  48. explicit in_place_type_t() = default;
  49. };
  50. template <std::size_t I>
  51. struct in_place_index_t // NOLINT(readability-identifier-naming)
  52. {
  53. explicit in_place_index_t() = default;
  54. };
  55. //===----------------------------------------------------------------------===//
  56. // Features from C++20
  57. //===----------------------------------------------------------------------===//
  58. template <typename T>
  59. struct remove_cvref // NOLINT(readability-identifier-naming)
  60. {
  61. using type = std::remove_cv_t<std::remove_reference_t<T>>;
  62. };
  63. template <typename T>
  64. using remove_cvref_t // NOLINT(readability-identifier-naming)
  65. = typename llvm::remove_cvref<T>::type;
  66. } // namespace llvm
  67. #endif // LLVM_ADT_STLFORWARDCOMPAT_H