From 56fb956015314c0fc0aa6942556c0eafa4e74b0a Mon Sep 17 00:00:00 2001 From: Alisdair Meredith Date: Tue, 7 May 2024 14:00:32 -0400 Subject: [PATCH] [memory.syn][specialized.algorithms] Prefer trailing returns on complex signatures This proposed change follows the observation that when function template signatures get complicated, especially with long names for return types, and non-trivial requires clauses, it can be very hard to spot the function name and return type among the sea of tokens, in order to start mentally parsing the function. Here we propose using the trailing return type form of function declaration in those cases, and apply it consistently to the special algorithms in the '' header as a non-trivial sample size to gauge interest in a more complete PR that would cover the whole ranges library. --- source/algorithms.tex | 73 ++++++++++++----------- source/memory.tex | 134 ++++++++++++++++++++++-------------------- 2 files changed, 107 insertions(+), 100 deletions(-) diff --git a/source/algorithms.tex b/source/algorithms.tex index 58377c00dd..27816db9fd 100644 --- a/source/algorithms.tex +++ b/source/algorithms.tex @@ -11105,10 +11105,10 @@ namespace ranges { template<@\exposconcept{nothrow-forward-iterator}@ I, @\exposconcept{nothrow-sentinel-for}@ S> requires @\libconcept{default_initializable}@> - I uninitialized_default_construct(I first, S last); + auto uninitialized_default_construct(I first, S last) -> I; template<@\exposconcept{nothrow-forward-range}@ R> requires @\libconcept{default_initializable}@> - borrowed_iterator_t uninitialized_default_construct(R&& r); + auto uninitialized_default_construct(R&& r) -> borrowed_iterator_t; } \end{itemdecl} @@ -11126,7 +11126,8 @@ \indexlibraryglobal{uninitialized_default_construct_n}% \begin{itemdecl} template - NoThrowForwardIterator uninitialized_default_construct_n(NoThrowForwardIterator first, Size n); + auto uninitialized_default_construct_n(NoThrowForwardIterator first, Size n) + -> NoThrowForwardIterator; \end{itemdecl} \begin{itemdescr} @@ -11146,7 +11147,7 @@ namespace ranges { template<@\exposconcept{nothrow-forward-iterator}@ I> requires @\libconcept{default_initializable}@> - I uninitialized_default_construct_n(I first, iter_difference_t n); + auto uninitialized_default_construct_n(I first, iter_difference_t n) -> I; } \end{itemdecl} @@ -11184,10 +11185,10 @@ namespace ranges { template<@\exposconcept{nothrow-forward-iterator}@ I, @\exposconcept{nothrow-sentinel-for}@ S> requires @\libconcept{default_initializable}@> - I uninitialized_value_construct(I first, S last); + auto uninitialized_value_construct(I first, S last) -> I; template<@\exposconcept{nothrow-forward-range}@ R> requires @\libconcept{default_initializable}@> - borrowed_iterator_t uninitialized_value_construct(R&& r); + auto uninitialized_value_construct(R&& r) -> borrowed_iterator_t; } \end{itemdecl} @@ -11205,7 +11206,8 @@ \indexlibraryglobal{uninitialized_value_construct_n}% \begin{itemdecl} template - NoThrowForwardIterator uninitialized_value_construct_n(NoThrowForwardIterator first, Size n); + auto uninitialized_value_construct_n(NoThrowForwardIterator first, Size n) + -> NoThrowForwardIterator; \end{itemdecl} \begin{itemdescr} @@ -11225,7 +11227,7 @@ namespace ranges { template<@\exposconcept{nothrow-forward-iterator}@ I> requires @\libconcept{default_initializable}@> - I uninitialized_value_construct_n(I first, iter_difference_t n); + auto uninitialized_value_construct_n(I first, iter_difference_t n) -> I; } \end{itemdecl} @@ -11244,8 +11246,8 @@ \indexlibraryglobal{uninitialized_copy}% \begin{itemdecl} template - NoThrowForwardIterator uninitialized_copy(InputIterator first, InputIterator last, - NoThrowForwardIterator result); + auto uninitialized_copy(InputIterator first, InputIterator last, NoThrowForwardIterator result) + -> NoThrowForwardIterator; \end{itemdecl} \begin{itemdescr} @@ -11273,12 +11275,12 @@ template<@\libconcept{input_iterator}@ I, @\libconcept{sentinel_for}@ S1, @\exposconcept{nothrow-forward-iterator}@ O, @\exposconcept{nothrow-sentinel-for}@ S2> requires @\libconcept{constructible_from}@, iter_reference_t> - uninitialized_copy_result - uninitialized_copy(I ifirst, S1 ilast, O ofirst, S2 olast); + auto uninitialized_copy(I ifirst, S1 ilast, O ofirst, S2 olast) + -> uninitialized_copy_result; template<@\libconcept{input_range}@ IR, @\exposconcept{nothrow-forward-range}@ OR> requires @\libconcept{constructible_from}@, range_reference_t> - uninitialized_copy_result, borrowed_iterator_t> - uninitialized_copy(IR&& in_range, OR&& out_range); + auto uninitialized_copy(IR&& in_range, OR&& out_range); + -> uninitialized_copy_result, borrowed_iterator_t> } \end{itemdecl} @@ -11300,8 +11302,8 @@ \indexlibraryglobal{uninitialized_copy_n}% \begin{itemdecl} template - NoThrowForwardIterator uninitialized_copy_n(InputIterator first, Size n, - NoThrowForwardIterator result); + auto uninitialized_copy_n(InputIterator first, Size n, NoThrowForwardIterator result) + -> NoThrowForwardIterator; \end{itemdecl} \begin{itemdescr} @@ -11328,8 +11330,8 @@ namespace ranges { template<@\libconcept{input_iterator}@ I, @\exposconcept{nothrow-forward-iterator}@ O, @\exposconcept{nothrow-sentinel-for}@ S> requires @\libconcept{constructible_from}@, iter_reference_t> - uninitialized_copy_n_result - uninitialized_copy_n(I ifirst, iter_difference_t n, O ofirst, S olast); + auto uninitialized_copy_n(I ifirst, iter_difference_t n, O ofirst, S olast) + -> uninitialized_copy_n_result; } \end{itemdecl} @@ -11354,8 +11356,8 @@ \indexlibraryglobal{uninitialized_move}% \begin{itemdecl} template - NoThrowForwardIterator uninitialized_move(InputIterator first, InputIterator last, - NoThrowForwardIterator result); + auto uninitialized_move(InputIterator first, InputIterator last, NoThrowForwardIterator result) + -> NoThrowForwardIterator; \end{itemdecl} \begin{itemdescr} @@ -11380,12 +11382,12 @@ template<@\libconcept{input_iterator}@ I, @\libconcept{sentinel_for}@ S1, @\exposconcept{nothrow-forward-iterator}@ O, @\exposconcept{nothrow-sentinel-for}@ S2> requires @\libconcept{constructible_from}@, iter_rvalue_reference_t> - uninitialized_move_result - uninitialized_move(I ifirst, S1 ilast, O ofirst, S2 olast); + auto uninitialized_move(I ifirst, S1 ilast, O ofirst, S2 olast) + -> uninitialized_move_result; template<@\libconcept{input_range}@ IR, @\exposconcept{nothrow-forward-range}@ OR> requires @\libconcept{constructible_from}@, range_rvalue_reference_t> - uninitialized_move_result, borrowed_iterator_t> - uninitialized_move(IR&& in_range, OR&& out_range); + auto uninitialized_move(IR&& in_range, OR&& out_range) + -> uninitialized_move_result, borrowed_iterator_t>; } \end{itemdecl} @@ -11414,8 +11416,8 @@ \indexlibraryglobal{uninitialized_move_n}% \begin{itemdecl} template - pair - uninitialized_move_n(InputIterator first, Size n, NoThrowForwardIterator result); + auto uninitialized_move_n(InputIterator first, Size n, NoThrowForwardIterator result) + -> pair; \end{itemdecl} \begin{itemdescr} @@ -11439,8 +11441,8 @@ namespace ranges { template<@\libconcept{input_iterator}@ I, @\exposconcept{nothrow-forward-iterator}@ O, @\exposconcept{nothrow-sentinel-for}@ S> requires @\libconcept{constructible_from}@, iter_rvalue_reference_t> - uninitialized_move_n_result - uninitialized_move_n(I ifirst, iter_difference_t n, O ofirst, S olast); + auto uninitialized_move_n(I ifirst, iter_difference_t n, O ofirst, S olast) + -> uninitialized_move_n_result; } \end{itemdecl} @@ -11490,10 +11492,10 @@ namespace ranges { template<@\exposconcept{nothrow-forward-iterator}@ I, @\exposconcept{nothrow-sentinel-for}@ S, class T> requires @\libconcept{constructible_from}@, const T&> - I uninitialized_fill(I first, S last, const T& x); + auto uninitialized_fill(I first, S last, const T& x) -> I; template<@\exposconcept{nothrow-forward-range}@ R, class T> requires @\libconcept{constructible_from}@, const T&> - borrowed_iterator_t uninitialized_fill(R&& r, const T& x); + auto uninitialized_fill(R&& r, const T& x) -> borrowed_iterator_t; } \end{itemdecl} @@ -11511,7 +11513,8 @@ \indexlibraryglobal{uninitialized_fill_n}% \begin{itemdecl} template - NoThrowForwardIterator uninitialized_fill_n(NoThrowForwardIterator first, Size n, const T& x); + auto uninitialized_fill_n(NoThrowForwardIterator first, Size n, const T& x) + -> NoThrowForwardIterator; \end{itemdecl} \begin{itemdescr} @@ -11531,7 +11534,7 @@ namespace ranges { template<@\exposconcept{nothrow-forward-iterator}@ I, class T> requires @\libconcept{constructible_from}@, const T&> - I uninitialized_fill_n(I first, iter_difference_t n, const T& x); + auto uninitialized_fill_n(I first, iter_difference_t n, const T& x) -> I; } \end{itemdecl} @@ -11615,10 +11618,10 @@ namespace ranges { template<@\exposconcept{nothrow-input-iterator}@ I, @\exposconcept{nothrow-sentinel-for}@ S> requires @\libconcept{destructible}@> - constexpr I destroy(I first, S last) noexcept; + constexpr auto destroy(I first, S last) noexcept -> I; template<@\exposconcept{nothrow-input-range}@ R> requires @\libconcept{destructible}@> - constexpr borrowed_iterator_t destroy(R&& r) noexcept; + constexpr auto destroy(R&& r) -> borrowed_iterator_t noexcept; } \end{itemdecl} @@ -11655,7 +11658,7 @@ namespace ranges { template<@\exposconcept{nothrow-input-iterator}@ I> requires @\libconcept{destructible}@> - constexpr I destroy_n(I first, iter_difference_t n) noexcept; + constexpr auto destroy_n(I first, iter_difference_t n) -> I noexcept; } \end{itemdecl} diff --git a/source/memory.tex b/source/memory.tex index 1a80d14ed0..165f63fa77 100644 --- a/source/memory.tex +++ b/source/memory.tex @@ -192,24 +192,25 @@ NoThrowForwardIterator first, NoThrowForwardIterator last); template - NoThrowForwardIterator - uninitialized_default_construct_n(NoThrowForwardIterator first, Size n); // freestanding + auto uninitialized_default_construct_n(NoThrowForwardIterator first, Size n) // freestanding + -> NoThrowForwardIterator; template - NoThrowForwardIterator - uninitialized_default_construct_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} - NoThrowForwardIterator first, Size n); + auto uninitialized_default_construct_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} + NoThrowForwardIterator first, Size n) + -> NoThrowForwardIterator; namespace ranges { template<@\exposconcept{nothrow-forward-iterator}@ I, @\exposconcept{nothrow-sentinel-for}@ S> requires @\libconcept{default_initializable}@> - I uninitialized_default_construct(I first, S last); // freestanding + auto uninitialized_default_construct(I first, S last) -> I; // freestanding template<@\exposconcept{nothrow-forward-range}@ R> requires @\libconcept{default_initializable}@> - borrowed_iterator_t uninitialized_default_construct(R&& r); // freestanding + auto uninitialized_default_construct(R&& r) -> borrowed_iterator_t; // freestanding template<@\exposconcept{nothrow-forward-iterator}@ I> requires @\libconcept{default_initializable}@> - I uninitialized_default_construct_n(I first, iter_difference_t n); // freestanding + auto uninitialized_default_construct_n(I first, iter_difference_t n) // freestanding + -> I; } template @@ -220,42 +221,44 @@ NoThrowForwardIterator first, NoThrowForwardIterator last); template - NoThrowForwardIterator - uninitialized_value_construct_n(NoThrowForwardIterator first, Size n); // freestanding + auto uninitialized_value_construct_n(NoThrowForwardIterator first, Size n) // freestanding + -> NoThrowForwardIterator; template - NoThrowForwardIterator - uninitialized_value_construct_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} - NoThrowForwardIterator first, Size n); + auto uninitialized_value_construct_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} + NoThrowForwardIterator first, Size n) + -> NoThrowForwardIterator; namespace ranges { template<@\exposconcept{nothrow-forward-iterator}@ I, @\exposconcept{nothrow-sentinel-for}@ S> requires @\libconcept{default_initializable}@> - I uninitialized_value_construct(I first, S last); // freestanding + auto uninitialized_value_construct(I first, S last) -> I; // freestanding template<@\exposconcept{nothrow-forward-range}@ R> requires @\libconcept{default_initializable}@> - borrowed_iterator_t uninitialized_value_construct(R&& r); // freestanding + auto uninitialized_value_construct(R&& r) -> borrowed_iterator_t; // freestanding template<@\exposconcept{nothrow-forward-iterator}@ I> requires @\libconcept{default_initializable}@> - I uninitialized_value_construct_n(I first, iter_difference_t n); // freestanding + auto uninitialized_value_construct_n(I first, iter_difference_t n) -> I; // freestanding } template - NoThrowForwardIterator uninitialized_copy(InputIterator first, // freestanding - InputIterator last, - NoThrowForwardIterator result); + auto uninitialized_copy(InputIterator first, InputIterator last, // freestanding + NoThrowForwardIterator result) + -> NoThrowForwardIterator; template - NoThrowForwardIterator uninitialized_copy(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} - ForwardIterator first, ForwardIterator last, - NoThrowForwardIterator result); + auto uninitialized_copy(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} + ForwardIterator first, ForwardIterator last, + NoThrowForwardIterator result) + -> NoThrowForwardIterator; template - NoThrowForwardIterator uninitialized_copy_n(InputIterator first, Size n, // freestanding - NoThrowForwardIterator result); + auto uninitialized_copy_n(InputIterator first, Size n, // freestanding + NoThrowForwardIterator result) + -> NoThrowForwardIterator; template - NoThrowForwardIterator uninitialized_copy_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} - ForwardIterator first, Size n, - NoThrowForwardIterator result); + auto uninitialized_copy_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} + ForwardIterator first, Size n, NoThrowForwardIterator result) + -> NoThrowForwardIterator; namespace ranges { template @@ -263,39 +266,39 @@ template<@\libconcept{input_iterator}@ I, @\libconcept{sentinel_for}@ S1, @\exposconcept{nothrow-forward-iterator}@ O, @\exposconcept{nothrow-sentinel-for}@ S2> requires @\libconcept{constructible_from}@, iter_reference_t> - uninitialized_copy_result - uninitialized_copy(I ifirst, S1 ilast, O ofirst, S2 olast); // freestanding + auto uninitialized_copy(I ifirst, S1 ilast, O ofirst, S2 olast) // freestanding + -> uninitialized_copy_result; template<@\libconcept{input_range}@ IR, @\exposconcept{nothrow-forward-range}@ OR> requires @\libconcept{constructible_from}@, range_reference_t> - uninitialized_copy_result, borrowed_iterator_t> - uninitialized_copy(IR&& in_range, OR&& out_range); // freestanding + auto uninitialized_copy(IR&& in_range, OR&& out_range) // freestanding + -> uninitialized_copy_result, borrowed_iterator_t>; template using uninitialized_copy_n_result = in_out_result; // freestanding template<@\libconcept{input_iterator}@ I, @\exposconcept{nothrow-forward-iterator}@ O, @\exposconcept{nothrow-sentinel-for}@ S> requires @\libconcept{constructible_from}@, iter_reference_t> - uninitialized_copy_n_result - uninitialized_copy_n(I ifirst, iter_difference_t n, // freestanding - O ofirst, S olast); + auto uninitialized_copy_n(I ifirst, iter_difference_t n, // freestanding + O ofirst, S olast) + -> uninitialized_copy_n_result; } template - NoThrowForwardIterator uninitialized_move(InputIterator first, // freestanding - InputIterator last, - NoThrowForwardIterator result); + auto uninitialized_move(InputIterator first, InputIterator last, // freestanding + NoThrowForwardIterator result) + -> NoThrowForwardIterator; template NoThrowForwardIterator uninitialized_move(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} ForwardIterator first, ForwardIterator last, NoThrowForwardIterator result); template - pair - uninitialized_move_n(InputIterator first, Size n, // freestanding - NoThrowForwardIterator result); + auto uninitialized_move_n(InputIterator first, Size n, // freestanding + NoThrowForwardIterator result); + -> pair template - pair - uninitialized_move_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} - ForwardIterator first, Size n, NoThrowForwardIterator result); + auto uninitialized_move_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} + ForwardIterator first, Size n, NoThrowForwardIterator result); + -> pair; namespace ranges { template @@ -303,21 +306,21 @@ template<@\libconcept{input_iterator}@ I, @\libconcept{sentinel_for}@ S1, @\exposconcept{nothrow-forward-iterator}@ O, @\exposconcept{nothrow-sentinel-for}@ S2> requires @\libconcept{constructible_from}@, iter_rvalue_reference_t> - uninitialized_move_result - uninitialized_move(I ifirst, S1 ilast, O ofirst, S2 olast); // freestanding + auto uninitialized_move(I ifirst, S1 ilast, O ofirst, S2 olast) // freestanding + -> uninitialized_move_result; template<@\libconcept{input_range}@ IR, @\exposconcept{nothrow-forward-range}@ OR> requires @\libconcept{constructible_from}@, range_rvalue_reference_t> - uninitialized_move_result, borrowed_iterator_t> - uninitialized_move(IR&& in_range, OR&& out_range); // freestanding + auto uninitialized_move(IR&& in_range, OR&& out_range) // freestanding + -> uninitialized_move_result, borrowed_iterator_t>; template using uninitialized_move_n_result = in_out_result; // freestanding template<@\libconcept{input_iterator}@ I, @\exposconcept{nothrow-forward-iterator}@ O, @\exposconcept{nothrow-sentinel-for}@ S> requires @\libconcept{constructible_from}@, iter_rvalue_reference_t> - uninitialized_move_n_result - uninitialized_move_n(I ifirst, iter_difference_t n, // freestanding - O ofirst, S olast); + auto uninitialized_move_n(I ifirst, iter_difference_t n, // freestanding + O ofirst, S olast) + -> uninitialized_move_n_result; } template @@ -328,24 +331,25 @@ NoThrowForwardIterator first, NoThrowForwardIterator last, const T& x); template - NoThrowForwardIterator - uninitialized_fill_n(NoThrowForwardIterator first, Size n, const T& x); // freestanding + auto uninitialized_fill_n(NoThrowForwardIterator first, Size n, const T& x) // freestanding + -> NoThrowForwardIterator; template - NoThrowForwardIterator - uninitialized_fill_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} - NoThrowForwardIterator first, Size n, const T& x); + auto uninitialized_fill_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} + NoThrowForwardIterator first, Size n, const T& x) + -> NoThrowForwardIterator; namespace ranges { template<@\exposconcept{nothrow-forward-iterator}@ I, @\exposconcept{nothrow-sentinel-for}@ S, class T> requires @\libconcept{constructible_from}@, const T&> - I uninitialized_fill(I first, S last, const T& x); // freestanding + auto uninitialized_fill(I first, S last, const T& x) -> I; // freestanding template<@\exposconcept{nothrow-forward-range}@ R, class T> requires @\libconcept{constructible_from}@, const T&> - borrowed_iterator_t uninitialized_fill(R&& r, const T& x); // freestanding + auto uninitialized_fill(R&& r, const T& x) -> borrowed_iterator_t; // freestanding template<@\exposconcept{nothrow-forward-iterator}@ I, class T> requires @\libconcept{constructible_from}@, const T&> - I uninitialized_fill_n(I first, iter_difference_t n, const T& x); // freestanding + auto uninitialized_fill_n(I first, iter_difference_t n, const T& x) // freestanding + -> I; } // \ref{specialized.construct}, \tcode{construct_at} @@ -367,11 +371,11 @@ void destroy(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} NoThrowForwardIterator first, NoThrowForwardIterator last); template - constexpr NoThrowForwardIterator destroy_n(NoThrowForwardIterator first, // freestanding - Size n); + onstexpr auto destroy_n(NoThrowForwardIterator first, Size n) // freestanding + -> NoThrowForwardIterator; template - NoThrowForwardIterator destroy_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} - NoThrowForwardIterator first, Size n); + auto destroy_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads} + NoThrowForwardIterator first, Size n) -> NoThrowForwardIterator; namespace ranges { template<@\libconcept{destructible}@ T> @@ -379,14 +383,14 @@ template<@\exposconcept{nothrow-input-iterator}@ I, @\exposconcept{nothrow-sentinel-for}@ S> requires @\libconcept{destructible}@> - constexpr I destroy(I first, S last) noexcept; // freestanding + constexpr auto destroy(I first, S last) noexcept -> I; // freestanding template<@\exposconcept{nothrow-input-range}@ R> requires @\libconcept{destructible}@> - constexpr borrowed_iterator_t destroy(R&& r) noexcept; // freestanding + constexpr auto destroy(R&& r) noexcept -> borrowed_iterator_t; // freestanding template<@\exposconcept{nothrow-input-iterator}@ I> requires @\libconcept{destructible}@> - constexpr I destroy_n(I first, iter_difference_t n) noexcept; // freestanding + constexpr auto I destroy_n(I first, iter_difference_t n) noexcept -> I; // freestanding } // \ref{unique.ptr}, class template \tcode{unique_ptr}