Skip to content

Commit

Permalink
Merge 2024-11 LWG Motion 1
Browse files Browse the repository at this point in the history
P3504R0 C++ Standard Library Ready Issues to be moved in Wrocław, Nov. 2024
  • Loading branch information
tkoeppe authored Dec 16, 2024
2 parents 1358c8c + 71389a0 commit 6d81ed8
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 146 deletions.
33 changes: 25 additions & 8 deletions source/algorithms.tex
Original file line number Diff line number Diff line change
Expand Up @@ -11167,13 +11167,20 @@

\pnum
Some algorithms specified in \ref{specialized.algorithms}
make use of the exposition-only function template
\tcode{\placeholdernc{voidify}}:
make use of the following exposition-only function templates:
\begin{codeblock}
template<class T>
constexpr void* @\placeholdernc{voidify}@(T& obj) noexcept {
return addressof(obj);
}

template<class I>
decltype(auto) @\exposid{deref-move}@(I& it) {
if constexpr (is_lvalue_reference_v<decltype(*it)>)
return std::move(*it);
else
return *it;
}
\end{codeblock}

\rSec2[special.mem.concepts]{Special memory concepts}
Expand Down Expand Up @@ -11550,7 +11557,7 @@
\begin{codeblock}
for (; first != last; (void)++result, ++first)
::new (@\placeholdernc{voidify}@(*result))
typename iterator_traits<NoThrowForwardIterator>::value_type(std::move(*first));
typename iterator_traits<NoThrowForwardIterator>::value_type(@\exposid{deref-move}@(first));
return result;
\end{codeblock}
\end{itemdescr}
Expand Down Expand Up @@ -11610,7 +11617,7 @@
\begin{codeblock}
for (; n > 0; ++result, (void) ++first, --n)
::new (@\placeholdernc{voidify}@(*result))
typename iterator_traits<NoThrowForwardIterator>::value_type(std::move(*first));
typename iterator_traits<NoThrowForwardIterator>::value_type(@\exposid{deref-move}@(first));
return {first, result};
\end{codeblock}
\end{itemdescr}
Expand Down Expand Up @@ -11741,14 +11748,22 @@
\begin{itemdescr}
\pnum
\constraints
The expression \tcode{::new (declval<void*>()) T(declval<Args>()...)}
\tcode{is_unbounded_array_v<T>} is \tcode{false}.
The expression \tcode{::new (declval<void*>()) T(\linebreak{}declval<Args>()...)}
is well-formed when treated as an unevaluated operand\iref{term.unevaluated.operand}.

\pnum
\mandates
If \tcode{is_array_v<T>} is \tcode{true}, \tcode{sizeof...(Args)} is zero.

\pnum
\effects
Equivalent to:
\begin{codeblock}
return ::new (@\placeholdernc{voidify}@(*location)) T(std::forward<Args>(args)...);
if constexpr (is_array_v<T>)
return ::new (@\placeholdernc{voidify}@(*location)) T[1]();
else
return ::new (@\placeholdernc{voidify}@(*location)) T(std::forward<Args>(args)...);
\end{codeblock}
\end{itemdescr}

Expand Down Expand Up @@ -11919,7 +11934,8 @@
\begin{itemdecl}
template<class R, class G, class D>
requires @\libconcept{output_range}@<R, invoke_result_t<D&, G&>> && @\libconcept{invocable}@<D&, G&> &&
@\libconcept{uniform_random_bit_generator}@<remove_cvref_t<G>>
@\libconcept{uniform_random_bit_generator}@<remove_cvref_t<G>> &&
is_arithmetic_v<invoke_result_t<D&, G&>>
constexpr borrowed_iterator_t<R> ranges::generate_random(R&& r, G&& g, D&& d);
\end{itemdecl}

Expand Down Expand Up @@ -11968,7 +11984,8 @@

\begin{itemdecl}
template<class G, class D, @\libconcept{output_iterator}@<invoke_result_t<D&, G&>> O, @\libconcept{sentinel_for}@<O> S>
requires @\libconcept{invocable}@<D&, G&> && @\libconcept{uniform_random_bit_generator}@<remove_cvref_t<G>>
requires @\libconcept{invocable}@<D&, G&> && @\libconcept{uniform_random_bit_generator}@<remove_cvref_t<G>> &&
is_arithmetic_v<invoke_result_t<D&, G&>>
constexpr O ranges::generate_random(O first, S last, G&& g, D&& d);
\end{itemdecl}

Expand Down
19 changes: 10 additions & 9 deletions source/containers.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@
\pnum
\expects
\tcode{T} is \oldconcept{EmplaceConstructible} into \tcode{X} from \tcode{args}.
For \tcode{vector} and \tcode{deque},
For \tcode{vector}, \tcode{inplace_vector}, and \tcode{deque},
\tcode{T} is also \oldconcept{MoveInsertable} into \tcode{X} and
\oldconcept{MoveAssignable}.

Expand Down Expand Up @@ -7200,10 +7200,13 @@
\rSec3[forward.list.modifiers]{Modifiers}

\pnum
None of the overloads of \tcode{insert_after} shall affect the validity of iterators and
references, and \tcode{erase_after} shall invalidate only iterators and references to
the erased elements. If an exception is thrown during \tcode{insert_after} there shall
be no effect. Inserting \tcode{n} elements into a \tcode{forward_list} is linear in
The member functions in this subclause
do not affect the validity of iterators and references
when inserting elements, and when erasing elements
invalidate iterators and references to the erased elements only.
If an exception is thrown by any of these member functions
there is no effect on the container.
Inserting \tcode{n} elements into a \tcode{forward_list} is linear in
\tcode{n}, and the number of calls to the copy or move constructor of \tcode{T} is
exactly equal to \tcode{n}. Erasing \tcode{n} elements from a \tcode{forward_list} is
linear in \tcode{n} and the number of calls to the destructor of type \tcode{T} is
Expand Down Expand Up @@ -7780,7 +7783,7 @@
\begin{itemdescr}
\pnum
\effects
Equivalent to: \tcode{return erase_if(c, [\&](auto\& elem) \{ return elem == value; \});}
Equivalent to: \tcode{return erase_if(c, [\&](const auto\& elem) -> bool \{ return elem == value; \});}
\end{itemdescr}

\indexlibrarymember{erase_if}{forward_list}%
Expand Down Expand Up @@ -8564,7 +8567,7 @@
\begin{itemdescr}
\pnum
\effects
Equivalent to: \tcode{return erase_if(c, [\&](auto\& elem) \{ return elem == value; \});}
Equivalent to: \tcode{return erase_if(c, [\&](const auto\& elem) -> bool \{ return elem == value; \});}
\end{itemdescr}

\indexlibrarymember{erase_if}{list}%
Expand Down Expand Up @@ -9255,8 +9258,6 @@

// bit reference
class @\libmember{reference}{vector<bool>}@ {
constexpr reference() noexcept;

public:
constexpr reference(const reference&) = default;
constexpr ~reference();
Expand Down
45 changes: 25 additions & 20 deletions source/iostreams.tex
Original file line number Diff line number Diff line change
Expand Up @@ -6816,7 +6816,7 @@
\effects
Equivalent to:
\begin{codeblock}
print(os, "{}\n", format(fmt, std::forward<Args>(args)...));
print(os, "{}\n", format(os.getloc(), fmt, std::forward<Args>(args)...));
\end{codeblock}
\end{itemdescr}

Expand Down Expand Up @@ -6854,25 +6854,31 @@
without regard to the value of \tcode{os.exceptions()} and
without turning on \tcode{ios_base::badbit} in the error state of \tcode{os}.
\end{itemize}

\par % This paragraph is part of the \effects clause.
After constructing a \tcode{sentry} object,
the function initializes a variable with automatic storage duration via
\begin{codeblock}
string out = vformat(os.getloc(), fmt, args);
\end{codeblock}
\begin{itemize}
\item
If the function is \tcode{vprint_unicode} and
\tcode{os} is a stream that refers to a terminal capable of displaying Unicode
\tcode{os} is a stream that refers to a terminal that
is capable of displaying Unicode only via a native Unicode API,
which is determined in an implementation-defined manner,
flushes \tcode{os} and then
writes \tcode{out} to the terminal using the native Unicode API;
if \tcode{out} contains invalid code units,
\indextext{undefined}%
the behavior is undefined and
implementations are encouraged to diagnose it.
If the native Unicode API is used,
the function flushes \tcode{os} before writing \tcode{out}.
Otherwise (if \tcode{os} is not such a stream or
the function is \tcode{vprint_nonunicode}),
the behavior is undefined.
\item
Otherwise
inserts the character sequence
\range{out.begin()}{out.end()} into \tcode{os}.
\end{itemize}

\par % This paragraph is part of the \effects clause.
If writing to the terminal or inserting into \tcode{os} fails,
calls \tcode{os.setstate(ios_base::badbit)}
(which may throw \tcode{ios_base::failure}).
Expand Down Expand Up @@ -7837,28 +7843,27 @@
Let \tcode{out} denote the character representation of
formatting arguments provided by \tcode{args}
formatted according to specifications given in \tcode{fmt}.
If \tcode{stream} refers to a terminal capable of displaying Unicode,
\begin{itemize}
\item
If \tcode{stream} refers to a terminal that
is capable of displaying Unicode only via a native Unicode API,
flushes \tcode{stream} and then
writes \tcode{out} to the terminal using the native Unicode API;
if \tcode{out} contains invalid code units,
\indextext{undefined}%
the behavior is undefined and
implementations are encouraged to diagnose it.
the behavior is undefined.
\item
Otherwise writes \tcode{out} to \tcode{stream} unchanged.
If the native Unicode API is used,
the function flushes \tcode{stream} before writing \tcode{out}.
\end{itemize}
Unconditionally unlocks \tcode{stream} on function exit.

\xrefc{7.21.2}.

\begin{note}
On POSIX and Windows, \tcode{stream} referring to a terminal means that,
respectively,
\tcode{isatty(fileno(\linebreak{}stream))} and
On Windows the native Unicode API is \tcode{WriteConsoleW} and
\tcode{stream} referring to a terminal means that
\tcode{GetConsoleMode(_get_osfhandle(_fileno(stream)), ...)}
return nonzero.
\end{note}
\begin{note}
On Windows, the native Unicode API is \tcode{WriteConsoleW}.
returns nonzero.
\end{note}

\pnum
Expand Down
1 change: 1 addition & 0 deletions source/iterators.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,7 @@
\item \tcode{to_address(a) == addressof(*a)},
\item \tcode{to_address(b) == to_address(a) + D(b - a)},
\item \tcode{to_address(c) == to_address(a) + D(c - a)},
\item \tcode{to_address(I\{\})} is well-defined,
\item \tcode{ranges::iter_move(a)} has
the same type, value category, and effects as \tcode{std::move(*a)}, and
\item if \tcode{ranges::iter_swap(a, b)} is well-formed,
Expand Down
60 changes: 37 additions & 23 deletions source/memory.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,14 @@
}
\end{codeblock}

\pnum
A program that instantiates the definition of \tcode{unique_ptr<T, D>}
is ill-formed if \tcode{T*} is an invalid type.
\begin{note}
This prevents the intantiation of specializations such as
\tcode{unique_ptr<T\&, D>} and \tcode{unique_ptr<int() const, D>}.
\end{note}

\pnum
The default type for the template parameter \tcode{D} is
\tcode{default_delete}. A client-supplied template argument
Expand Down Expand Up @@ -2434,9 +2442,13 @@
\end{itemdecl}

\begin{itemdescr}
\pnum
\mandates
\tcode{reference_converts_from_temporary_v<add_lvalue_reference_t<T>, decltype(\linebreak{}*declval<pointer>())>} is \tcode{false}.

\pnum
\expects
\tcode{get() != nullptr}.
\tcode{get() != nullptr} is \tcode{true}.

\pnum
\returns
Expand Down Expand Up @@ -3970,15 +3982,15 @@
\tcode{allocate_shared} shall initialize this (sub)object
via the expression
\begin{itemize}
\item \tcode{allocator_traits<A2>::construct(a2, pv, v)} or
\item \tcode{allocator_traits<A2>::construct(a2, pv, l...)}
\item \tcode{allocator_traits<A2>::construct(a2, pu, v)} or
\item \tcode{allocator_traits<A2>::construct(a2, pu, l...)}
\end{itemize}
respectively,
where \tcode{pv} points to storage
suitable to hold an object of type \tcode{U} and
\tcode{a2} of type \tcode{A2} is a rebound copy of
the allocator \tcode{a} passed to \tcode{allocate_shared}
such that its \tcode{value_type} is \tcode{remove_cv_t<U>}.
where \tcode{pu} is a pointer of type \tcode{remove_cv_t<U>*}
pointing to storage
suitable to hold an object of type \tcode{remove_cv_t<U>} and
\tcode{a2} of type \tcode{A2} is a potentially rebound copy of
the allocator \tcode{a} passed to \tcode{allocate_shared}.
\item
When a (sub)object of non-array type \tcode{U} is specified to have
a default initial value,
Expand All @@ -3989,13 +4001,13 @@
\item
When a (sub)object of non-array type \tcode{U} is specified to have
a default initial value,
\tcode{allocate_shared} shall initialize this (sub)object
via the expression \tcode{allocator_traits<A2>::construct(a2, pv)},
where \tcode{pv} points to storage
suitable to hold an object of type \tcode{U} and
\tcode{a2} of type \tcode{A2} is a rebound copy of
the allocator \tcode{a} passed to \tcode{allocate_shared}
such that its \tcode{value_type} is \tcode{remove_cv_t<U>}.
\tcode{allocate_shared} initializes this (sub)object
via the expression \tcode{allocator_traits<A2>::construct(a2, pu)},
where \tcode{pu} is a pointer of type \tcode{remove_cv_t<U>*}
pointing to storage
suitable to hold an object of type \tcode{remove_cv_t<U>} and
\tcode{a2} of type \tcode{A2} is a potentially rebound copy of
the allocator \tcode{a} passed to \tcode{allocate_shared}.
\item
When a (sub)object of non-array type \tcode{U} is initialized by
\tcode{make_shared_for_overwrite} or\linebreak % avoid Overfull
Expand All @@ -4012,18 +4024,20 @@
of their original construction.
\item
When a (sub)object of non-array type \tcode{U}
that was initialized by \tcode{make_shared} is to be destroyed,
it is destroyed via the expression \tcode{pv->\~{}U()} where
\tcode{pv} points to that object of type \tcode{U}.
that was initialized by \tcode{make_shared},
\tcode{make_shared_for_overwrite}, or \tcode{allocate_shared_for_overwrite}
is to be destroyed,
it is destroyed via the expression \tcode{pu->\~{}U()} where
\tcode{pu} points to that object of type \tcode{U}.
\item
When a (sub)object of non-array type \tcode{U}
that was initialized by \tcode{allocate_shared} is to be destroyed,
it is destroyed via the expression
\tcode{allocator_traits<A2>::destroy(a2, pv)} where
\tcode{pv} points to that object of type \tcode{remove_cv_t<U>} and
\tcode{a2} of type \tcode{A2} is a rebound copy of
the allocator \tcode{a} passed to \tcode{allocate_shared}
such that its \tcode{value_type} is \tcode{remove_cv_t<U>}.
\tcode{allocator_traits<A2>::destroy(a2, pu)} where
\tcode{pu} is a pointer of type \tcode{remove_cv_t<U>*}
pointing to that object of type \tcode{remove_cv_t<U>} and
\tcode{a2} of type \tcode{A2} is a potentially rebound copy of
the allocator \tcode{a} passed to \tcode{allocate_shared}.
\end{itemize}
\begin{note}
These functions will typically allocate more memory than \tcode{sizeof(T)} to
Expand Down
4 changes: 2 additions & 2 deletions source/meta.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,8 @@
For an array type \tcode{T}, the same result as
\tcode{has_unique_object_representations_v<remove_all_extents_t<T>>},
otherwise \seebelow. &
\tcode{T} shall be a complete type, \cv{}~\keyword{void}, or
an array of unknown bound. \\ \rowsep
\tcode{remove_all_extents_t<T>} shall be a complete type or
\cv{}~\keyword{void}. \\ \rowsep

\indexlibraryglobal{reference_constructs_from_temporary}%
\tcode{template<class T, class U>}\br
Expand Down
Loading

0 comments on commit 6d81ed8

Please sign in to comment.