constructible.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 > 17
  19. // [concept.constructible]
  20. template<class _Tp, class... _Args>
  21. concept constructible_from =
  22. destructible<_Tp> && is_constructible_v<_Tp, _Args...>;
  23. // [concept.default.init]
  24. template<class _Tp>
  25. concept __default_initializable = requires { ::new _Tp; };
  26. template<class _Tp>
  27. concept default_initializable = constructible_from<_Tp> &&
  28. requires { _Tp{}; } && __default_initializable<_Tp>;
  29. // [concept.moveconstructible]
  30. template<class _Tp>
  31. concept move_constructible =
  32. constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
  33. // [concept.copyconstructible]
  34. template<class _Tp>
  35. concept copy_constructible =
  36. move_constructible<_Tp> &&
  37. constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp> &&
  38. constructible_from<_Tp, const _Tp&> && convertible_to<const _Tp&, _Tp> &&
  39. constructible_from<_Tp, const _Tp> && convertible_to<const _Tp, _Tp>;
  40. #endif // _LIBCPP_STD_VER > 17
  41. _LIBCPP_END_NAMESPACE_STD
  42. #endif // _LIBCPP___CONCEPTS_CONSTRUCTIBLE_H