Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/support.tex
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@
#define @\defnlibxname{cpp_lib_find_last}@ 202207L // also in \libheader{algorithm}
#define @\defnlibxname{cpp_lib_flat_map}@ 202207L // also in \libheader{flat_map}
#define @\defnlibxname{cpp_lib_format}@ 202207L // also in \libheader{format}
#define @\defnlibxname{cpp_lib_forward_like}@ 202207L // also in \libheader{utility}
#define @\defnlibxname{cpp_lib_gcd_lcm}@ 201606L // also in \libheader{numeric}
#define @\defnlibxname{cpp_lib_generic_associative_lookup}@ 201304L // also in \libheader{map}, \libheader{set}
#define @\defnlibxname{cpp_lib_generic_unordered_lookup}@ 201811L
Expand Down
53 changes: 53 additions & 0 deletions source/utilities.tex
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
constexpr T&& forward(remove_reference_t<T>& t) noexcept;
template<class T>
constexpr T&& forward(remove_reference_t<T>&& t) noexcept;
template<class T, class U>
[[nodiscard]] constexpr auto forward_like(U&& x) noexcept -> @\seebelow@;
template<class T>
constexpr remove_reference_t<T>&& move(T&&) noexcept;
template<class T>
Expand Down Expand Up @@ -358,6 +360,57 @@
\end{example}
\end{itemdescr}

\indexlibraryglobal{forward_like}%
\begin{itemdecl}
template<class T, class U>
[[nodiscard]] constexpr auto forward_like(U&& x) noexcept -> @\seebelow@;
\end{itemdecl}

\begin{itemdescr}
\pnum
\begin{itemize}
\item
Let \tcode{\exposid{COPY_CONST}(A, B)} be \tcode{const B}
if \tcode{A} is a const type, otherwise \tcode{B}.
\item
Let \tcode{\exposid{OVERRIDE_REF}(A, B)} be \tcode{remove_reference_t<B>\&\&}
if \tcode{A} is an rvalue reference type, otherwise \tcode{B\&}.
\item
Let \tcode{V} be
\begin{codeblock}
@\exposid{OVERRIDE_REF}@(T&&, @\exposid{COPY_CONST}@(remove_reference_t<T>, remove_reference_t<U>))
\end{codeblock}
\end{itemize}

\pnum
\returns
\tcode{static_cast<V>(x)}.

\pnum
\remarks
The return type is \tcode{V}.

\pnum
\begin{example}
\begin{codeblock}
struct accessor {
vector<string>* container;
decltype(auto) operator[](this auto&& self, size_t i) {
return std::forward_like<decltype(self)>((*container)[i]);
}
};
void g() {
vector v{"a"s, "b"s};
accessor a{&v};
string& x = a[0]; // OK, binds to lvalue reference
string&& y = std::move(a)[0]; // OK, is rvalue reference
string const&& z = std::move(as_const(a))[1]; // OK, is \tcode{const\&\&}
string& w = as_const(a)[1]; // error: will not bind to non-const
}
\end{codeblock}
\end{example}
\end{itemdescr}

\indexlibrary{\idxcode{move}!function}%
\indextext{\idxcode{move}}%
\begin{itemdecl}
Expand Down