[libcxx][modularisation] moves <utility> content out of <type_traits>

Moves:

* `std::move`, `std::forward`, `std::declval`, and `std::swap` into
  `__utility/${FUNCTION_NAME}`.
* `std::swap_ranges` and `std::iter_swap` into
  `__algorithm/${FUNCTION_NAME}`

Differential Revision: https://reviews.llvm.org/D103734
This commit is contained in:
Christopher Di Bella 2021-06-05 02:47:47 +00:00
parent d87f159ab6
commit 6adbc83ee9
73 changed files with 403 additions and 125 deletions

View File

@ -34,6 +34,7 @@ set(files
__algorithm/is_permutation.h
__algorithm/is_sorted.h
__algorithm/is_sorted_until.h
__algorithm/iter_swap.h
__algorithm/lexicographical_compare.h
__algorithm/lower_bound.h
__algorithm/make_heap.h
@ -85,6 +86,7 @@ set(files
__algorithm/sort_heap.h
__algorithm/stable_partition.h
__algorithm/stable_sort.h
__algorithm/swap_ranges.h
__algorithm/transform.h
__algorithm/unique_copy.h
__algorithm/unique.h
@ -157,6 +159,11 @@ set(files
__tree
__tuple
__undef_macros
__utility/__decay_copy.h
__utility/declval.h
__utility/forward.h
__utility/move.h
__utility/swap.h
__utility/to_underlying.h
algorithm
any

View File

@ -17,6 +17,7 @@
#include <__algorithm/min.h>
#include <__algorithm/upper_bound.h>
#include <__iterator/iterator_traits.h>
#include <__utility/swap.h>
#include <memory>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

View File

@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___ALGORITHM_ITER_SWAP_H
#define _LIBCPP___ALGORITHM_ITER_SWAP_H
#include <__config>
#include <__utility/declval.h>
#include <__utility/swap.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void iter_swap(_ForwardIterator1 __a,
_ForwardIterator2 __b)
// _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
_NOEXCEPT_(_NOEXCEPT_(swap(*declval<_ForwardIterator1>(), *declval<_ForwardIterator2>()))) {
swap(*__a, *__b);
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___ALGORITHM_ITER_SWAP_H

View File

@ -11,6 +11,7 @@
#include <__config>
#include <__algorithm/unwrap_iter.h>
#include <__utility/move.h>
#include <cstring>
#include <utility>
#include <type_traits>

View File

@ -14,7 +14,7 @@
#include <__algorithm/comp_ref_type.h>
#include <__algorithm/reverse.h>
#include <__iterator/iterator_traits.h>
#include <type_traits> // swap
#include <__utility/swap.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header

View File

@ -14,7 +14,7 @@
#include <__algorithm/comp_ref_type.h>
#include <__algorithm/sort.h>
#include <__iterator/iterator_traits.h>
#include <type_traits> // swap
#include <__utility/swap.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header

View File

@ -16,7 +16,7 @@
#include <__algorithm/sift_down.h>
#include <__algorithm/sort_heap.h>
#include <__iterator/iterator_traits.h>
#include <type_traits> // swap
#include <__utility/swap.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header

View File

@ -11,6 +11,8 @@
#include <__config>
#include <__iterator/iterator_traits.h>
#include <__utility/swap.h>
#include <utility> // pair
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

View File

@ -14,7 +14,7 @@
#include <__algorithm/comp_ref_type.h>
#include <__algorithm/sift_down.h>
#include <__iterator/iterator_traits.h>
#include <type_traits> // swap
#include <__utility/swap.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header

View File

@ -14,7 +14,7 @@
#include <__algorithm/comp_ref_type.h>
#include <__algorithm/reverse.h>
#include <__iterator/iterator_traits.h>
#include <type_traits> // swap
#include <__utility/swap.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header

View File

@ -13,7 +13,7 @@
#include <__algorithm/comp.h>
#include <__algorithm/comp_ref_type.h>
#include <__iterator/iterator_traits.h>
#include <type_traits> // swap
#include <__utility/move.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header

View File

@ -11,8 +11,8 @@
#include <__config>
#include <__algorithm/find.h>
#include <utility>
#include <type_traits>
#include <__algorithm/find_if.h>
#include <__utility/move.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header

View File

@ -10,8 +10,8 @@
#define _LIBCPP___ALGORITHM_REVERSE_H
#include <__config>
#include <__algorithm/iter_swap.h>
#include <__iterator/iterator_traits.h>
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header

View File

@ -11,11 +11,13 @@
#include <__algorithm/move.h>
#include <__algorithm/move_backward.h>
#include <__algorithm/swap_ranges.h>
#include <__config>
#include <__iterator/iterator_traits.h>
#include <__iterator/next.h>
#include <__iterator/prev.h>
#include <type_traits>
#include <__utility/swap.h>
#include <iterator>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header

View File

@ -12,6 +12,7 @@
#include <__config>
#include <__algorithm/move.h>
#include <__algorithm/move_backward.h>
#include <__algorithm/swap_ranges.h>
#include <__iterator/iterator_traits.h>
#include <type_traits> // swap

View File

@ -12,9 +12,9 @@
#include <__config>
#include <__iterator/iterator_traits.h>
#include <__random/uniform_int_distribution.h>
#include <__utility/swap.h>
#include <cstddef>
#include <cstdint>
#include <type_traits> // swap
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header

View File

@ -11,8 +11,7 @@
#include <__config>
#include <__iterator/iterator_traits.h>
#include <utility>
#include <type_traits>
#include <__utility/move.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header

View File

@ -15,6 +15,7 @@
#include <__algorithm/min_element.h>
#include <__algorithm/partial_sort.h>
#include <__algorithm/unwrap_iter.h>
#include <__utility/swap.h>
#include <memory>
#include <type_traits> // swap

View File

@ -12,6 +12,7 @@
#include <__config>
#include <__algorithm/rotate.h>
#include <__iterator/iterator_traits.h>
#include <__utility/swap.h>
#include <memory>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

View File

@ -15,6 +15,7 @@
#include <__algorithm/inplace_merge.h>
#include <__algorithm/sort.h>
#include <__iterator/iterator_traits.h>
#include <__utility/swap.h>
#include <memory>
#include <type_traits> // swap

View File

@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___ALGORITHM_SWAP_RANGES_H
#define _LIBCPP___ALGORITHM_SWAP_RANGES_H
#include <__config>
#include <__utility/swap.h>
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator2
swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
for (; __first1 != __last1; ++__first1, (void)++__first2)
swap(*__first1, *__first2);
return __first2;
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___ALGORITHM_SWAP_RANGES_H

View File

@ -13,7 +13,7 @@
#include <__algorithm/comp.h>
#include <__algorithm/adjacent_find.h>
#include <__iterator/iterator_traits.h>
#include <utility>
#include <__utility/move.h>
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

View File

@ -16,6 +16,7 @@
#include <__iterator/iterator_traits.h>
#include <__iterator/readable_traits.h>
#include <__memory/pointer_traits.h>
#include <__utility/forward.h>
#include <concepts>
#include <type_traits>

View File

@ -12,6 +12,7 @@
#include <__config>
#include <__iterator/iterator_traits.h>
#include <__utility/forward.h>
#include <concepts> // __class_or_enum
#include <type_traits>
#include <utility>

View File

@ -12,6 +12,7 @@
#include <__config>
#include <__memory/allocator_traits.h>
#include <__utility/forward.h>
#include <cstddef>
#include <new>
#include <stdexcept>

View File

@ -13,6 +13,7 @@
#include <__config>
#include <__memory/construct_at.h>
#include <__memory/pointer_traits.h>
#include <__utility/forward.h>
#include <limits>
#include <type_traits>

View File

@ -11,6 +11,7 @@
#define _LIBCPP___MEMORY_COMPRESSED_PAIR_H
#include <__config>
#include <__utility/forward.h>
#include <tuple> // needed in c++03 for some constructors
#include <type_traits>
#include <utility>

View File

@ -12,6 +12,7 @@
#include <__config>
#include <__debug>
#include <__utility/forward.h>
#include <utility>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

View File

@ -20,6 +20,7 @@
#include <__memory/compressed_pair.h>
#include <__memory/pointer_traits.h>
#include <__memory/unique_ptr.h>
#include <__utility/forward.h>
#include <cstddef>
#include <cstdlib> // abort
#include <iosfwd>

View File

@ -14,6 +14,7 @@
#include <__functional_base> // std::less
#include <__memory/allocator_traits.h> // __pointer
#include <__memory/compressed_pair.h>
#include <__utility/forward.h>
#include <cstddef>
#include <type_traits>
#include <utility>

View File

@ -13,6 +13,8 @@
#include <__iterator/concepts.h>
#include <__iterator/readable_traits.h>
#include <__ranges/enable_borrowed_range.h>
#include <__utility/__decay_copy.h>
#include <__utility/forward.h>
#include <concepts>
#include <type_traits>

View File

@ -16,6 +16,8 @@
#include <__ranges/concepts.h>
#include <__ranges/ref_view.h>
#include <__ranges/subrange.h>
#include <__utility/__decay_copy.h>
#include <__utility/forward.h>
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

View File

@ -14,6 +14,7 @@
#include <__iterator/iterator_traits.h>
#include <__memory/pointer_traits.h>
#include <__ranges/access.h>
#include <__utility/forward.h>
#include <concepts>
#include <type_traits>

View File

@ -13,6 +13,7 @@
#include <__iterator/concepts.h>
#include <__ranges/access.h>
#include <__ranges/size.h>
#include <__utility/forward.h>
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

View File

@ -13,6 +13,8 @@
#include <__iterator/concepts.h>
#include <__iterator/iterator_traits.h>
#include <__ranges/access.h>
#include <__utility/__decay_copy.h>
#include <__utility/forward.h>
#include <concepts>
#include <type_traits>

View File

@ -3,6 +3,7 @@
#define _LIBCPP_SPLIT_BUFFER
#include <__config>
#include <__utility/forward.h>
#include <algorithm>
#include <type_traits>

View File

@ -11,6 +11,7 @@
#define _LIBCPP___TREE
#include <__config>
#include <__utility/forward.h>
#include <algorithm>
#include <iterator>
#include <memory>

View File

@ -0,0 +1,39 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___TYPE_TRAITS_DECAY_COPY_H
#define _LIBCPP___TYPE_TRAITS_DECAY_COPY_H
#include <__config>
#include <__utility/forward.h>
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY typename decay<_Tp>::type __decay_copy(_Tp&& __t)
#if _LIBCPP_STD_VER > 17
noexcept(is_nothrow_convertible_v<_Tp, remove_reference_t<_Tp> >)
#endif
{
return _VSTD::forward<_Tp>(__t);
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___TYPE_TRAITS_DECAY_COPY_H

View File

@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___UTILITY_DECLVAL_H
#define _LIBCPP___UTILITY_DECLVAL_H
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
// Suppress deprecation notice for volatile-qualified return type resulting
// from volatile-qualified types _Tp.
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
template <class _Tp>
_Tp&& __declval(int);
template <class _Tp>
_Tp __declval(long);
_LIBCPP_SUPPRESS_DEPRECATED_POP
template <class _Tp>
decltype(__declval<_Tp>(0)) declval() _NOEXCEPT;
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___UTILITY_DECLVAL_H

View File

@ -0,0 +1,42 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___UTILITY_FORWARD_H
#define _LIBCPP___UTILITY_FORWARD_H
#include <__config>
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _Tp&&
forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT {
return static_cast<_Tp&&>(__t);
}
template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _Tp&&
forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT {
static_assert(!is_lvalue_reference<_Tp>::value, "cannot forward an rvalue as an lvalue");
return static_cast<_Tp&&>(__t);
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___UTILITY_FORWARD_H

View File

@ -0,0 +1,52 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___UTILITY_MOVE_H
#define _LIBCPP___UTILITY_MOVE_H
#include <__config>
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename remove_reference<_Tp>::type&&
move(_Tp&& __t) _NOEXCEPT {
typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type _Up;
return static_cast<_Up&&>(__t);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
using __move_if_noexcept_result_t =
typename conditional<!is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, const _Tp&,
_Tp&&>::type;
#else // _LIBCPP_CXX03_LANG
template <class _Tp>
using __move_if_noexcept_result_t = const _Tp&;
#endif
template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 __move_if_noexcept_result_t<_Tp>
move_if_noexcept(_Tp& __x) _NOEXCEPT {
return _VSTD::move(__x);
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___UTILITY_MOVE_H

View File

@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___UTILITY_SWAP_H
#define _LIBCPP___UTILITY_SWAP_H
#include <__config>
#include <__utility/declval.h>
#include <__utility/move.h>
#include <type_traits>
#include <cstddef>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
using __swap_result_t = typename enable_if<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>::type;
#else
template <class>
using __swap_result_t = void;
#endif
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY __swap_result_t<_Tp> _LIBCPP_CONSTEXPR_AFTER_CXX17 swap(_Tp& __x, _Tp& __y)
_NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value&& is_nothrow_move_assignable<_Tp>::value) {
_Tp __t(_VSTD::move(__x));
__x = _VSTD::move(__y);
__y = _VSTD::move(__t);
}
template <class _Tp, size_t _Np>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if<__is_swappable<_Tp>::value>::type
swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
for (size_t __i = 0; __i != _Np; ++__i) {
swap(__a[__i], __b[__i]);
}
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___UTILITY_SWAP_H

View File

@ -695,6 +695,7 @@ template <class BidirectionalIterator, class Compare>
#include <__algorithm/is_permutation.h>
#include <__algorithm/is_sorted.h>
#include <__algorithm/is_sorted_until.h>
#include <__algorithm/iter_swap.h>
#include <__algorithm/lexicographical_compare.h>
#include <__algorithm/lower_bound.h>
#include <__algorithm/make_heap.h>
@ -746,6 +747,7 @@ template <class BidirectionalIterator, class Compare>
#include <__algorithm/sort_heap.h>
#include <__algorithm/stable_partition.h>
#include <__algorithm/stable_sort.h>
#include <__algorithm/swap_ranges.h>
#include <__algorithm/transform.h>
#include <__algorithm/unique_copy.h>
#include <__algorithm/unique.h>

View File

@ -82,6 +82,7 @@ namespace std {
#include <__availability>
#include <__config>
#include <__utility/forward.h>
#include <cstdlib>
#include <memory>
#include <type_traits>

View File

@ -163,6 +163,7 @@ template <class T, class Allocator, class Predicate>
#include <__config>
#include <__debug>
#include <__split_buffer>
#include <__utility/forward.h>
#include <algorithm>
#include <compare>
#include <initializer_list>

View File

@ -266,7 +266,7 @@ struct __throw_with_nested<_Tp, _Up, true> {
_LIBCPP_NORETURN static inline _LIBCPP_INLINE_VISIBILITY void
__do_throw(_Tp&& __t)
{
throw __nested<_Up>(_VSTD::forward<_Tp>(__t));
throw __nested<_Up>(static_cast<_Tp&&>(__t));
}
};
@ -279,7 +279,7 @@ struct __throw_with_nested<_Tp, _Up, false> {
__do_throw (_Tp& __t)
#endif // _LIBCPP_CXX03_LANG
{
throw _VSTD::forward<_Tp>(__t);
throw static_cast<_Tp&&>(__t);
}
};
#endif
@ -296,7 +296,7 @@ throw_with_nested(_Tp&& __t)
is_class<_Up>::value &&
!is_base_of<nested_exception, _Up>::value &&
!__libcpp_is_final<_Up>::value>::
__do_throw(_VSTD::forward<_Tp>(__t));
__do_throw(static_cast<_Tp&&>(__t));
#else
((void)__t);
// FIXME: Make this abort

View File

@ -56,6 +56,9 @@ namespace std {
#if _LIBCPP_STD_VER > 11
#include <__memory/addressof.h>
#include <__utility/move.h>
#include <__utility/forward.h>
#include <iterator>
_LIBCPP_BEGIN_NAMESPACE_LFTS

View File

@ -232,6 +232,7 @@
#include <__availability>
#include <__config>
#include <__debug>
#include <__utility/forward.h>
#include <chrono>
#include <compare>
#include <cstddef>

View File

@ -180,6 +180,7 @@ template <class T, class Allocator, class Predicate>
*/
#include <__config>
#include <__utility/forward.h>
#include <algorithm>
#include <initializer_list>
#include <iterator>

View File

@ -491,6 +491,7 @@ POLICY: For non-variadic implementations, the number of arguments is limited
#include <__debug>
#include <__functional_base>
#include <__functional/search.h>
#include <__utility/forward.h>
#include <concepts>
#include <exception>
#include <memory>

View File

@ -364,6 +364,8 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
#include <__availability>
#include <__config>
#include <__debug>
#include <__utility/__decay_copy.h>
#include <__utility/forward.h>
#include <chrono>
#include <exception>
#include <memory>

View File

@ -159,6 +159,7 @@ template <class Stream, class T>
*/
#include <__config>
#include <__utility/forward.h>
#include <ostream>
#include <version>

View File

@ -570,6 +570,7 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
#include <__iterator/readable_traits.h>
#include <__memory/addressof.h>
#include <__memory/pointer_traits.h>
#include <__utility/forward.h>
#include <compare>
#include <concepts> // Mandated by the Standard.
#include <cstddef>

View File

@ -182,6 +182,7 @@ template <class T, class Allocator, class Predicate>
#include <__config>
#include <__debug>
#include <__utility/forward.h>
#include <algorithm>
#include <initializer_list>
#include <iterator>

View File

@ -493,6 +493,7 @@ erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
#include <__debug>
#include <__node_handle>
#include <__tree>
#include <__utility/forward.h>
#include <compare>
#include <functional>
#include <initializer_list>

View File

@ -666,9 +666,12 @@ module std [system] {
export *
module __utility {
module to_underlying {
header "__utility/to_underlying.h"
}
module __decay_copy { header "__utility/__decay_copy.h" }
module declval { header "__utility/declval.h" }
module forward { header "__utility/forward.h" }
module move { header "__utility/move.h" }
module swap { header "__utility/swap.h" }
module to_underlying { header "__utility/to_underlying.h" }
}
}
module valarray {

View File

@ -189,6 +189,7 @@ template<class Callable, class ...Args>
#include <__config>
#include <__mutex_base>
#include <__threading_support>
#include <__utility/forward.h>
#include <cstdint>
#include <functional>
#include <memory>

View File

@ -179,6 +179,7 @@ template <class T, class Container, class Compare>
*/
#include <__config>
#include <__utility/forward.h>
#include <algorithm>
#include <compare>
#include <deque>

View File

@ -106,6 +106,7 @@ template <class OuterA1, class OuterA2, class... InnerAllocs>
*/
#include <__config>
#include <__utility/forward.h>
#include <memory>
#include <version>

View File

@ -437,6 +437,7 @@ erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
#include <__debug>
#include <__node_handle>
#include <__tree>
#include <__utility/forward.h>
#include <compare>
#include <functional>
#include <initializer_list>

View File

@ -88,6 +88,7 @@ template <class T, class Container>
*/
#include <__config>
#include <__utility/forward.h>
#include <deque>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

View File

@ -87,6 +87,8 @@ void sleep_for(const chrono::duration<Rep, Period>& rel_time);
#include <__functional_base>
#include <__mutex_base>
#include <__threading_support>
#include <__utility/__decay_copy.h>
#include <__utility/forward.h>
#include <chrono>
#include <cstddef>
#include <functional>

View File

@ -151,6 +151,8 @@ template <class... Types>
#include <__config>
#include <__functional_base>
#include <__utility/forward.h>
#include <__utility/move.h>
#include <__tuple>
#include <compare>
#include <cstddef>

View File

@ -2818,46 +2818,6 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_destructible_v
#endif // __has_keyword(__is_destructible)
// move
template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename remove_reference<_Tp>::type&&
move(_Tp&& __t) _NOEXCEPT
{
typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type _Up;
return static_cast<_Up&&>(__t);
}
template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_Tp&&
forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT
{
return static_cast<_Tp&&>(__t);
}
template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_Tp&&
forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT
{
static_assert(!is_lvalue_reference<_Tp>::value,
"cannot forward an rvalue as an lvalue");
return static_cast<_Tp&&>(__t);
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename decay<_Tp>::type
__decay_copy(_Tp&& __t)
#if _LIBCPP_STD_VER > 17
noexcept(is_nothrow_convertible_v<_Tp, remove_reference_t<_Tp>>)
#endif
{
return static_cast<_Tp&&>(__t);
}
template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr>
struct __member_pointer_traits_imp
{
@ -4185,10 +4145,11 @@ _LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_r_v
#endif // _LIBCPP_STD_VER > 14
// __swappable
template <class _Tp> struct __is_swappable;
template <class _Tp> struct __is_nothrow_swappable;
// swap, swap_ranges
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
@ -4202,49 +4163,14 @@ template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 __swap_result_t<_Tp>
swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
is_nothrow_move_assignable<_Tp>::value)
{
_Tp __t(_VSTD::move(__x));
__x = _VSTD::move(__y);
__y = _VSTD::move(__t);
}
is_nothrow_move_assignable<_Tp>::value);
template<class _Tp, size_t _Np>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
typename enable_if<
__is_swappable<_Tp>::value
>::type
swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
{
for (size_t __i = 0; __i != _Np; ++__i) {
swap(__a[__i], __b[__i]);
}
}
template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator2
swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
{
for(; __first1 != __last1; ++__first1, (void) ++__first2)
swap(*__first1, *__first2);
return __first2;
}
// iter_swap
template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
void
iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
// _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
_NOEXCEPT_(_NOEXCEPT_(swap(*declval<_ForwardIterator1>(),
*declval<_ForwardIterator2>())))
{
swap(*__a, *__b);
}
// __swappable
swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value);
namespace __detail
{

View File

@ -435,6 +435,7 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
#include <__debug>
#include <__hash_table>
#include <__node_handle>
#include <__utility/forward.h>
#include <compare>
#include <functional>
#include <iterator> // __libcpp_erase_if_container

View File

@ -390,6 +390,7 @@ template <class Value, class Hash, class Pred, class Alloc>
#include <__debug>
#include <__hash_table>
#include <__node_handle>
#include <__utility/forward.h>
#include <compare>
#include <functional>
#include <iterator> // __libcpp_erase_if_container

View File

@ -210,6 +210,10 @@ template <class T>
#include <__config>
#include <__debug>
#include <__tuple>
#include <__utility/declval.h>
#include <__utility/forward.h>
#include <__utility/move.h>
#include <__utility/swap.h>
#include <__utility/to_underlying.h>
#include <compare>
#include <cstddef>
@ -266,29 +270,6 @@ operator>=(const _Tp& __x, const _Tp& __y)
} // rel_ops
// swap_ranges is defined in <type_traits>`
// swap is defined in <type_traits>
// move_if_noexcept
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
using __move_if_noexcept_result_t =
typename conditional<!is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, const _Tp&,
_Tp&&>::type;
#else // _LIBCPP_CXX03_LANG
template <class _Tp>
using __move_if_noexcept_result_t = const _Tp&;
#endif
template <class _Tp>
_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
__move_if_noexcept_result_t<_Tp> move_if_noexcept(_Tp& __x) _NOEXCEPT
{
return _VSTD::move(__x);
}
#if _LIBCPP_STD_VER > 14
template <class _Tp>
_LIBCPP_NODISCARD_EXT constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; }

View File

@ -201,6 +201,7 @@ namespace std {
#include <__availability>
#include <__config>
#include <__utility/forward.h>
#include <__tuple>
#include <array>
#include <compare>

View File

@ -276,6 +276,7 @@ erase_if(vector<T, Allocator>& c, Predicate pred); // C++20
#include <__debug>
#include <__functional_base>
#include <__split_buffer>
#include <__utility/forward.h>
#include <algorithm>
#include <climits>
#include <compare>

View File

@ -23,7 +23,7 @@ int main(int, char**)
{
{
std::forward<A&>(source()); // expected-note {{requested here}}
// expected-error-re@type_traits:* 1 {{static_assert failed{{.*}} "cannot forward an rvalue as an lvalue"}}
// expected-error-re@*:* 1 {{static_assert failed{{.*}} "cannot forward an rvalue as an lvalue"}}
}
{
const A ca = A();

View File

@ -13,9 +13,10 @@
// void
// swap(T& a, T& b);
#include <utility>
#include <cassert>
#include <memory>
#include <type_traits>
#include <utility>
#include "test_macros.h"

View File

@ -13,9 +13,11 @@
// void
// swap(T (&a)[N], T (&b)[N]);
#include <utility>
#include <algorithm>
#include <cassert>
#include <memory>
#include <type_traits>
#include <utility>
#include "test_macros.h"

View File

@ -9,8 +9,9 @@
#ifndef SUPPORT_POISONED_HASH_HELPER_H
#define SUPPORT_POISONED_HASH_HELPER_H
#include <type_traits>
#include <__utility/move.h> // TODO: replace with <utility> when std::hash is moved out of the header
#include <cassert>
#include <type_traits>
#include "test_macros.h"
#include "test_workarounds.h"