in_place.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===----------------------------------------------------------------------===//
  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. #ifndef _LIBCPP___UTILITY_IN_PLACE_H
  9. #define _LIBCPP___UTILITY_IN_PLACE_H
  10. #include <__config>
  11. #include <__type_traits/remove_cvref.h>
  12. #include <cstddef>
  13. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  14. # pragma GCC system_header
  15. #endif
  16. _LIBCPP_BEGIN_NAMESPACE_STD
  17. #if _LIBCPP_STD_VER > 14
  18. struct _LIBCPP_TYPE_VIS in_place_t {
  19. explicit in_place_t() = default;
  20. };
  21. inline constexpr in_place_t in_place{};
  22. template <class _Tp>
  23. struct _LIBCPP_TEMPLATE_VIS in_place_type_t {
  24. explicit in_place_type_t() = default;
  25. };
  26. template <class _Tp>
  27. inline constexpr in_place_type_t<_Tp> in_place_type{};
  28. template <size_t _Idx>
  29. struct _LIBCPP_TEMPLATE_VIS in_place_index_t {
  30. explicit in_place_index_t() = default;
  31. };
  32. template <size_t _Idx>
  33. inline constexpr in_place_index_t<_Idx> in_place_index{};
  34. template <class _Tp> struct __is_inplace_type_imp : false_type {};
  35. template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {};
  36. template <class _Tp>
  37. using __is_inplace_type = __is_inplace_type_imp<__remove_cvref_t<_Tp>>;
  38. template <class _Tp> struct __is_inplace_index_imp : false_type {};
  39. template <size_t _Idx> struct __is_inplace_index_imp<in_place_index_t<_Idx>> : true_type {};
  40. template <class _Tp>
  41. using __is_inplace_index = __is_inplace_index_imp<__remove_cvref_t<_Tp>>;
  42. #endif // _LIBCPP_STD_VER > 14
  43. _LIBCPP_END_NAMESPACE_STD
  44. #endif // _LIBCPP___UTILITY_IN_PLACE_H