Skip to content

Commit

Permalink
P0784R7 Library Support For More constexpr Containers (#1369)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Bucior <35536269+AdamBucior@users.noreply.github.com>
Co-authored-by: Curtis Jacques Bezault <curtbezault@gmail.com>
Co-authored-by: Michael Schellenberger Costa <mschellenbergercosta@gmail.com>
Co-authored-by: mnatsuhara <46756417+mnatsuhara@users.noreply.github.com>
Co-authored-by: Stephan T. Lavavej <stl@microsoft.com>
  • Loading branch information
6 people authored Jan 8, 2021
1 parent 54cce5e commit 2561974
Show file tree
Hide file tree
Showing 8 changed files with 472 additions and 118 deletions.
47 changes: 8 additions & 39 deletions stl/inc/memory
Original file line number Diff line number Diff line change
Expand Up @@ -496,22 +496,7 @@ namespace ranges {
};

inline constexpr _Uninitialized_fill_n_fn uninitialized_fill_n{_Not_quite_object::_Construct_tag{}};
} // namespace ranges
#endif // __cpp_lib_concepts

// FUNCTION TEMPLATE construct_at
#if _HAS_CXX20
template <class _Ty, class... _Types>
_CONSTEXPR20_DYNALLOC auto construct_at(_Ty* const _Location, _Types&&... _Args) noexcept(
noexcept(::new (const_cast<void*>(static_cast<const volatile void*>(_Location)))
_Ty(_STD forward<_Types>(_Args)...))) // strengthened
-> decltype(
::new (const_cast<void*>(static_cast<const volatile void*>(_Location))) _Ty(_STD forward<_Types>(_Args)...)) {
return ::new (const_cast<void*>(static_cast<const volatile void*>(_Location))) _Ty(_STD forward<_Types>(_Args)...);
}

#ifdef __cpp_lib_concepts
namespace ranges {
// VARIABLE ranges::construct_at
class _Construct_at_fn : private _Not_quite_object {
public:
Expand All @@ -532,26 +517,7 @@ namespace ranges {
};

inline constexpr _Construct_at_fn construct_at{_Not_quite_object::_Construct_tag{}};
} // namespace ranges
#endif // __cpp_lib_concepts
#endif // _HAS_CXX20

#if _HAS_CXX17
// FUNCTION TEMPLATE destroy_at
template <class _Ty>
_CONSTEXPR20_DYNALLOC void destroy_at(_Ty* const _Location) noexcept /* strengthened */ {
#if _HAS_CXX20
if constexpr (is_array_v<_Ty>) {
_Destroy_range(_STD begin(*_Location), _STD end(*_Location));
} else
#endif // _HAS_CXX20
{
_Location->~_Ty();
}
}

#ifdef __cpp_lib_concepts
namespace ranges {
// VARIABLE ranges::destroy_at
// clang-format off
template <_No_throw_input_iterator _It, _No_throw_sentinel_for<_It> _Se>
Expand All @@ -577,9 +543,11 @@ namespace ranges {
} // namespace ranges
#endif // __cpp_lib_concepts

#if _HAS_CXX17
// FUNCTION TEMPLATE destroy
template <class _NoThrowFwdIt>
void destroy(const _NoThrowFwdIt _First, const _NoThrowFwdIt _Last) { // destroy all elements in [_First, _Last)
_CONSTEXPR20_DYNALLOC void destroy(const _NoThrowFwdIt _First, const _NoThrowFwdIt _Last) {
// destroy all elements in [_First, _Last)
_Adl_verify_range(_First, _Last);
_Destroy_range(_Get_unwrapped(_First), _Get_unwrapped(_Last));
}
Expand All @@ -606,7 +574,7 @@ namespace ranges {
// clang-format off
template <_No_throw_input_iterator _It, _No_throw_sentinel_for<_It> _Se>
requires destructible<iter_value_t<_It>>
/* _CONSTEXPR20_DYNALLOC */ _It operator()(_It _First, _Se _Last) const noexcept {
_CONSTEXPR20_DYNALLOC _It operator()(_It _First, _Se _Last) const noexcept {
// clang-format on
_Adl_verify_range(_First, _Last);
_Seek_wrapped(_First,
Expand All @@ -617,7 +585,7 @@ namespace ranges {
// clang-format off
template <_No_throw_input_range _Rng>
requires destructible<range_value_t<_Rng>>
/* _CONSTEXPR20_DYNALLOC */ borrowed_iterator_t<_Rng> operator()(_Rng&& _Range) const noexcept {
_CONSTEXPR20_DYNALLOC borrowed_iterator_t<_Rng> operator()(_Rng&& _Range) const noexcept {
// clang-format on
auto _First = _RANGES begin(_Range);
_Seek_wrapped(_First, _RANGES _Destroy_unchecked(_Get_unwrapped(_STD move(_First)), _Uend(_Range)));
Expand All @@ -631,7 +599,7 @@ namespace ranges {

// FUNCTION TEMPLATE destroy_n
template <class _NoThrowFwdIt, class _Diff>
_NoThrowFwdIt destroy_n(_NoThrowFwdIt _First, const _Diff _Count_raw) {
_CONSTEXPR20_DYNALLOC _NoThrowFwdIt destroy_n(_NoThrowFwdIt _First, const _Diff _Count_raw) {
// destroy all elements in [_First, _First + _Count)
_Algorithm_int_t<_Diff> _Count = _Count_raw;
if (_Count <= 0) {
Expand Down Expand Up @@ -661,8 +629,9 @@ namespace ranges {
// clang-format off
template <_No_throw_input_iterator _It>
requires destructible<iter_value_t<_It>>
/* _CONSTEXPR20_DYNALLOC */ _It operator()(_It _First, const iter_difference_t<_It> _Count) const noexcept {
_CONSTEXPR20_DYNALLOC _It operator()(_It _First, const iter_difference_t<_It> _Count_raw) const noexcept {
// clang-format on
_Algorithm_int_t<iter_difference_t<_It>> _Count = _Count_raw;
if (_Count <= 0) {
return _First;
}
Expand Down
Loading

0 comments on commit 2561974

Please sign in to comment.