Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LWG 3] P2407R5 Freestanding Library: Partial Classes #6702

Merged
merged 2 commits into from
Dec 17, 2023
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
4 changes: 2 additions & 2 deletions source/algorithms.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,7 @@
void fill(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads}
ForwardIterator first, ForwardIterator last, const T& value);
template<class OutputIterator, class Size, class T>
constexpr OutputIterator fill_n(OutputIterator first, Size n, const T& value);
constexpr OutputIterator fill_n(OutputIterator first, Size n, const T& value); // freestanding
template<class ExecutionPolicy, class ForwardIterator,
class Size, class T>
ForwardIterator fill_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads}
Expand Down Expand Up @@ -5207,7 +5207,7 @@
template<class ForwardIterator1, class ForwardIterator2>
constexpr ForwardIterator2
swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2);
ForwardIterator2 first2); // freestanding
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
ForwardIterator2
swap_ranges(ExecutionPolicy&& exec,
Expand Down
7 changes: 4 additions & 3 deletions source/containers.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5975,12 +5975,13 @@

\indexheader{array}%
\begin{codeblock}
// mostly freestanding
#include <compare> // see \ref{compare.syn}
#include <initializer_list> // see \ref{initializer.list.syn}

namespace std {
// \ref{array}, class template \tcode{array}
template<class T, size_t N> struct array;
template<class T, size_t N> struct array; // partially freestanding

template<class T, size_t N>
constexpr bool operator==(const array<T, N>& x, const array<T, N>& y);
Expand Down Expand Up @@ -6273,8 +6274,8 @@
// element access
constexpr reference operator[](size_type n);
constexpr const_reference operator[](size_type n) const;
constexpr reference at(size_type n);
constexpr const_reference at(size_type n) const;
constexpr reference at(size_type n); // freestanding-deleted
constexpr const_reference at(size_type n) const; // freestanding-deleted
constexpr reference front();
constexpr const_reference front() const;
constexpr reference back();
Expand Down
102 changes: 72 additions & 30 deletions source/lib-intro.tex
Original file line number Diff line number Diff line change
Expand Up @@ -901,29 +901,62 @@
Unless otherwise specified,
the requirements on freestanding items for a freestanding implementation
are the same as the corresponding requirements for a hosted implementation,
except that not all of the members of the namespaces are required to be present.
except that not all of the members of those items are required to be present.

\pnum
Function declarations and function template declarations
followed by a comment that include \textit{freestanding-deleted} are
\defnadjx{freestanding deleted}{functions}{function}.
On freestanding implementations,
it is \impldef{whether a freestanding deleted function is a deleted function}
whether each entity introduced by a freestanding deleted function
is a deleted function\iref{dcl.fct.def.delete} or
whether the requirements are the same as
the corresponding requirements for a hosted implementation.
\begin{note}
This implies that freestanding item enumerations have the same enumerators on
freestanding implementations and hosted implementations.
Furthermore, class types have the same members and
class templates have the same deduction guides
on freestanding implementations and hosted implementations.
Deleted definitions reduce the chance of overload resolution silently changing
when migrating from a freestanding implementation to a hosted implementation.
\end{note}
\begin{example}
\begin{codeblock}
double abs(double j); // freestanding-deleted
\end{codeblock}
\end{example}

\pnum
\indextext{declaration!freestanding item}%
A declaration in a header synopsis is a freestanding item if
A declaration in a synopsis is a freestanding item if
\begin{itemize}
\item it is followed by a comment that includes \textit{freestanding}, or
\item the header synopsis begins with a comment that includes \textit{all freestanding}.
\item it is followed by a comment that includes \textit{freestanding},
\item it is followed by a comment that includes \textit{freestanding-deleted}, or
\item the header synopsis begins with a comment
that includes \textit{freestanding} and
the declaration is not followed by a comment that includes \textit{hosted}.
\begin{note}
Declarations followed by \textit{hosted} in freestanding headers are
not freestanding items.
As a result, looking up the name of such functions can vary
between hosted and freestanding implementations.
\end{note}
\end{itemize}
\begin{example}
\begin{codeblock}
// all freestanding
namespace std {
\end{codeblock}
\end{example}

\pnum
\indextext{entity!freestanding item}%
\indextext{deduction guide!freestanding item}%
\indextext{\idxgram{typedef-name}!freestanding item}%
An entity or \grammarterm{typedef-name} is a freestanding item if it is:
An entity, deduction guide, or \grammarterm{typedef-name} is
a freestanding item if it is:
\begin{itemize}
\item introduced by a declaration that is a freestanding item,
\item a member of a freestanding item other than a namespace,
\item an enumerator of a freestanding item,
\item a deduction guide of a freestanding item,
\item an enclosing namespace of a freestanding item,
\item a friend of a freestanding item,
\item denoted by a \grammarterm{typedef-name} that is a freestanding item, or
Expand All @@ -934,35 +967,40 @@
\indextext{macro!freestanding item}%
A macro is a freestanding item if it is defined in a header synopsis and
\begin{itemize}
\item the definition is followed by a comment that includes \textit{freestanding}, or
\item the header synopsis begins with a comment that includes \textit{all freestanding}.
\item the definition is followed by a comment
that includes \textit{freestanding}, or
\item the header synopsis begins with a comment
that includes \textit{freestanding} and
the definition is not followed by a comment that includes \textit{hosted}.
\end{itemize}

\pnum
jensmaurer marked this conversation as resolved.
Show resolved Hide resolved
\begin{example}
\begin{codeblock}
#define NULL @\seebelow@ // freestanding
\end{codeblock}
\end{example}

\begin{example}
\begin{codeblock}
// all freestanding
namespace std {
\end{codeblock}
\end{example}

\pnum
Function declarations and function template declarations
followed by a comment that include \textit{freestanding-deleted} are
\defnadjx{freestanding deleted}{functions}{function}.
On freestanding implementations,
it is \impldef{whether a freestanding deleted function is a freestanding item or a deleted function}
whether each function definition introduced by a freestanding deleted function
is a freestanding item or a deleted function\iref{dcl.fct.def.delete}.
\begin{note}
Freestanding annotations follow some additional exposition conventions
that do not impose any additional normative requirements.
Header synopses that begin with a comment containing "all freestanding"
contain no hosted items and no freestanding deleted functions.
Header synopses that begin with a comment containing "mostly freestanding"
contain at least one hosted item or freestanding deleted function.
Classes and class templates followed by a comment
containing "partially freestanding"
contain at least one hosted item or freestanding deleted function.
\end{note}
\begin{example}
\begin{codeblock}
double abs(double j); // freestanding-deleted
template<class T, size_t N> struct array; // partially freestanding
template<class T, size_t N>
struct array {
constexpr reference operator[](size_type n);
constexpr const_reference operator[](size_type n) const;
constexpr reference at(size_type n); // freestanding-deleted
constexpr const_reference at(size_type n) const; // freestanding-deleted
};
\end{codeblock}
\end{example}

Expand Down Expand Up @@ -1485,14 +1523,18 @@
\ref{ratio} & Compile-time rational arithmetic & \tcode{<ratio>} \\ \rowsep
\ref{utility} & Utility components & \tcode{<utility>} \\ \rowsep
\ref{tuple} & Tuples & \tcode{<tuple>} \\ \rowsep
\ref{optional} & Optional objects & \tcode{<optional>} \\ \rowsep
\ref{variant} & Variants & \tcode{<variant>} \\ \rowsep
\ref{function.objects} & Function objects & \tcode{<functional>} \\ \rowsep
\ref{charconv} & Primitive numeric conversions & \tcode{<charconv>} \\ \rowsep
\ref{bit} & Bit manipulation & \tcode{<bit>} \\ \rowsep
\ref{string.view} & String view classes & \tcode{<string_view>} \\ \rowsep
\ref{string.classes} & String classes & \tcode{<string>} \\ \rowsep
\ref{c.strings} & Null-terminated sequence utilities & \tcode{<cstring>}, \tcode{<cwchar>} \\ \rowsep
\ref{array} & Class template \tcode{array} & \tcode{<array>} \\ \rowsep
\ref{iterators} & Iterators library & \tcode{<iterator>} \\ \rowsep
\ref{ranges} & Ranges library & \tcode{<ranges>} \\ \rowsep
\ref{algorithms} & Algorithms library & \tcode{<numeric>} \\ \rowsep
\ref{algorithms} & Algorithms library & \tcode{<algorithm>}, \tcode{<numeric>} \\ \rowsep
\ref{c.math} & Mathematical functions for floating-point types & \tcode{<cmath>} \\ \rowsep
\ref{atomics} & Atomics & \tcode{<atomic>} \\ \rowsep
\end{libsumtab}
Expand Down
46 changes: 29 additions & 17 deletions source/strings.tex
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,13 @@

\indexheader{string_view}%
\begin{codeblock}
// mostly freestanding
#include <compare> // see \ref{compare.syn}

namespace std {
// \ref{string.view.template}, class template \tcode{basic_string_view}
template<class charT, class traits = char_traits<charT>>
class basic_string_view;
class basic_string_view; // partially freestanding

template<class charT, class traits>
constexpr bool ranges::@\libspec{enable_view}{basic_string_view}@<basic_string_view<charT, traits>> = true;
Expand All @@ -559,7 +560,7 @@
template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
basic_string_view<charT, traits> str);
basic_string_view<charT, traits> str); // hosted

// \tcode{basic_string_view} \grammarterm{typedef-name}s
using string_view = basic_string_view<char>;
Expand Down Expand Up @@ -663,7 +664,7 @@

// \ref{string.view.access}, element access
constexpr const_reference operator[](size_type pos) const;
constexpr const_reference at(size_type pos) const;
constexpr const_reference at(size_type pos) const; // freestanding-deleted
constexpr const_reference front() const;
constexpr const_reference back() const;
constexpr const_pointer data() const noexcept;
Expand All @@ -674,17 +675,22 @@
constexpr void swap(basic_string_view& s) noexcept;

// \ref{string.view.ops}, string operations
constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
constexpr size_type copy(charT* s, size_type n,
size_type pos = 0) const; // freestanding-deleted

constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
constexpr basic_string_view substr(size_type pos = 0,
size_type n = npos) const; // freestanding-deleted

constexpr int compare(basic_string_view s) const noexcept;
constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
constexpr int compare(size_type pos1, size_type n1,
basic_string_view s) const; // freestanding-deleted
constexpr int compare(size_type pos1, size_type n1, basic_string_view s,
size_type pos2, size_type n2) const;
size_type pos2, size_type n2) const; // freestanding-deleted
constexpr int compare(const charT* s) const;
constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
constexpr int compare(size_type pos1, size_type n1,
const charT* s) const; // freestanding-deleted
constexpr int compare(size_type pos1, size_type n1, const charT* s,
size_type n2) const; // freestanding-deleted

constexpr bool starts_with(basic_string_view x) const noexcept;
constexpr bool starts_with(charT x) const noexcept;
Expand Down Expand Up @@ -1311,9 +1317,12 @@
\end{itemdecl}

\begin{itemdescr}
\pnum
Let \tcode{rlen} be the smaller of \tcode{size()} and \tcode{x.size()}.

\pnum
\effects
Equivalent to: \tcode{return substr(0, x.size()) == x;}
Equivalent to: \tcode{return basic_string_view(data(), rlen) == x;}
\end{itemdescr}

\indexlibrarymember{starts_with}{basic_string_view}%
Expand Down Expand Up @@ -1344,11 +1353,14 @@
\end{itemdecl}

\begin{itemdescr}
\pnum
Let \tcode{rlen} be the smaller of \tcode{size()} and \tcode{x.size()}.

\pnum
\effects
Equivalent to:
\begin{codeblock}
return size() >= x.size() && compare(size() - x.size(), npos, x) == 0;
return basic_string_view(data() + (size() - rlen), rlen) == x;
\end{codeblock}
\end{itemdescr}

Expand Down Expand Up @@ -1439,7 +1451,7 @@
\item
\tcode{xpos + str.size() <= size()}
\item
\tcode{traits::eq(at(xpos + I), str.at(I))} for all elements \tcode{I} of the string referenced by \tcode{str}.
\tcode{traits::eq(data_[xpos + I], str[I])} for all elements \tcode{I} of the string referenced by \tcode{str}.
\end{itemize}

\pnum
Expand All @@ -1466,7 +1478,7 @@
\item
\tcode{xpos + str.size() <= size()}
\item
\tcode{traits::eq(at(xpos + I), str.at(I))} for all elements \tcode{I} of the string referenced by \tcode{str}.
\tcode{traits::eq(data_[xpos + I], str[I])} for all elements \tcode{I} of the string referenced by \tcode{str}.
\end{itemize}

\pnum
Expand All @@ -1493,7 +1505,7 @@
\item
\tcode{xpos < size()}
\item
\tcode{traits::eq(at(xpos), str.at(I))} for some element \tcode{I} of the string referenced by \tcode{str}.
\tcode{traits::eq(data_[xpos], str[I])} for some element \tcode{I} of the string referenced by \tcode{str}.
\end{itemize}

\pnum
Expand All @@ -1520,7 +1532,7 @@
\item
\tcode{xpos < size()}
\item
\tcode{traits::eq(at(xpos), str.at(I))} for some element \tcode{I} of the string referenced by \tcode{str}.
\tcode{traits::eq(data_[xpos], str[I])} for some element \tcode{I} of the string referenced by \tcode{str}.
\end{itemize}

\pnum
Expand All @@ -1547,7 +1559,7 @@
\item
\tcode{xpos < size()}
\item
\tcode{traits::eq(at(xpos), str.at(I))} for no element \tcode{I} of the string referenced by \tcode{str}.
\tcode{traits::eq(data_[xpos], str[I])} for no element \tcode{I} of the string referenced by \tcode{str}.
\end{itemize}

\pnum
Expand All @@ -1573,7 +1585,7 @@
\item
\tcode{xpos < size()}
\item
\tcode{traits::eq(at(xpos), str.at(I))} for no element \tcode{I} of the string referenced by \tcode{str}.
\tcode{traits::eq(data_[xpos], str[I])} for no element \tcode{I} of the string referenced by \tcode{str}.
\end{itemize}

\pnum
Expand Down
6 changes: 6 additions & 0 deletions source/support.tex
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@
#define @\defnlibxname{cpp_lib_format_ranges}@ 202207L // also in \libheader{format}
#define @\defnlibxname{cpp_lib_formatters}@ 202302L // also in \libheader{stacktrace}, \libheader{thread}
#define @\defnlibxname{cpp_lib_forward_like}@ 202207L // freestanding, also in \libheader{utility}
#define @\defnlibxname{cpp_lib_freestanding_algorithm}@ 202311L
// freestanding, also in \libheader{algorithm}, \libheader{numeric}
#define @\defnlibxname{cpp_lib_freestanding_array}@ 202311L // freestanding, also in \libheader{array}
#define @\defnlibxname{cpp_lib_freestanding_char_traits}@ 202306L // freestanding, also in \libheader{string}
#define @\defnlibxname{cpp_lib_freestanding_charconv}@ 202306L // freestanding, also in \libheader{charconv}
#define @\defnlibxname{cpp_lib_freestanding_cstdlib}@ 202306L // freestanding, also in \libheader{cstdlib}, \libheader{cmath}
Expand All @@ -647,10 +650,13 @@
#define @\defnlibxname{cpp_lib_freestanding_iterator}@ 202306L // freestanding, also in \libheader{iterator}
#define @\defnlibxname{cpp_lib_freestanding_memory}@ 202306L // freestanding, also in \libheader{memory}
#define @\defnlibxname{cpp_lib_freestanding_operator_new}@ @\seebelow@ // freestanding, also in \libheader{new}
#define @\defnlibxname{cpp_lib_freestanding_optional}@ 202311L // freestanding, also in \libheader{optional}
#define @\defnlibxname{cpp_lib_freestanding_ranges}@ 202306L // freestanding, also in \libheader{ranges}
#define @\defnlibxname{cpp_lib_freestanding_ratio}@ 202306L // freestanding, also in \libheader{ratio}
#define @\defnlibxname{cpp_lib_freestanding_string_view}@ 202311L // freestanding, also in \libheader{string_view}
#define @\defnlibxname{cpp_lib_freestanding_tuple}@ 202306L // freestanding, also in \libheader{tuple}
#define @\defnlibxname{cpp_lib_freestanding_utility}@ 202306L // freestanding, also in \libheader{utility}
#define @\defnlibxname{cpp_lib_freestanding_variant}@ 202311L // freestanding, also in \libheader{variant}
#define @\defnlibxname{cpp_lib_fstream_native_handle}@ 202306L // also in \libheader{fstream}
#define @\defnlibxname{cpp_lib_function_ref}@ 202306L // also in \libheader{functional}
#define @\defnlibxname{cpp_lib_gcd_lcm}@ 201606L // also in \libheader{numeric}
Expand Down
Loading