STLForwardCompat.h 2.9 KB

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