constructible.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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___CONCEPTS_CONSTRUCTIBLE_H
  9. #define _LIBCPP___CONCEPTS_CONSTRUCTIBLE_H
  10. #include <__concepts/convertible_to.h>
  11. #include <__concepts/destructible.h>
  12. #include <__config>
  13. #include <__type_traits/is_constructible.h>
  14. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  15. # pragma GCC system_header
  16. #endif
  17. _LIBCPP_BEGIN_NAMESPACE_STD
  18. #if _LIBCPP_STD_VER >= 20
  19. // [concept.constructible]
  20. template <class _Tp, class... _Args>
  21. concept constructible_from = destructible<_Tp> && is_constructible_v<_Tp, _Args...>;
  22. // [concept.default.init]
  23. template <class _Tp>
  24. concept __default_initializable = requires { ::new _Tp; };
  25. template <class _Tp>
  26. concept default_initializable = constructible_from<_Tp> && requires { _Tp{}; } && __default_initializable<_Tp>;
  27. // [concept.moveconstructible]
  28. template <class _Tp>
  29. concept move_constructible = constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
  30. // [concept.copyconstructible]
  31. // clang-format off
  32. template <class _Tp>
  33. concept copy_constructible =
  34. move_constructible<_Tp> &&
  35. constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp> &&
  36. constructible_from<_Tp, const _Tp&> && convertible_to<const _Tp&, _Tp> &&
  37. constructible_from<_Tp, const _Tp> && convertible_to<const _Tp, _Tp>;
  38. // clang-format on
  39. #endif // _LIBCPP_STD_VER >= 20
  40. _LIBCPP_END_NAMESPACE_STD
  41. #endif // _LIBCPP___CONCEPTS_CONSTRUCTIBLE_H