Skip to content

Commit c44868c

Browse files
jensmaurertkoeppe
authored andcommitted
P2407R5 Freestanding Library: Partial Classes
1 parent 24c4b48 commit c44868c

File tree

6 files changed

+197
-97
lines changed

6 files changed

+197
-97
lines changed

source/algorithms.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,7 @@
16301630
void fill(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads}
16311631
ForwardIterator first, ForwardIterator last, const T& value);
16321632
template<class OutputIterator, class Size, class T>
1633-
constexpr OutputIterator fill_n(OutputIterator first, Size n, const T& value);
1633+
constexpr OutputIterator fill_n(OutputIterator first, Size n, const T& value); // freestanding
16341634
template<class ExecutionPolicy, class ForwardIterator,
16351635
class Size, class T>
16361636
ForwardIterator fill_n(ExecutionPolicy&& exec, // see \ref{algorithms.parallel.overloads}
@@ -5207,7 +5207,7 @@
52075207
template<class ForwardIterator1, class ForwardIterator2>
52085208
constexpr ForwardIterator2
52095209
swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
5210-
ForwardIterator2 first2);
5210+
ForwardIterator2 first2); // freestanding
52115211
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
52125212
ForwardIterator2
52135213
swap_ranges(ExecutionPolicy&& exec,

source/containers.tex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5975,12 +5975,13 @@
59755975

59765976
\indexheader{array}%
59775977
\begin{codeblock}
5978+
// mostly freestanding
59785979
#include <compare> // see \ref{compare.syn}
59795980
#include <initializer_list> // see \ref{initializer.list.syn}
59805981

59815982
namespace std {
59825983
// \ref{array}, class template \tcode{array}
5983-
template<class T, size_t N> struct array;
5984+
template<class T, size_t N> struct array; // partially freestanding
59845985

59855986
template<class T, size_t N>
59865987
constexpr bool operator==(const array<T, N>& x, const array<T, N>& y);
@@ -6273,8 +6274,8 @@
62736274
// element access
62746275
constexpr reference operator[](size_type n);
62756276
constexpr const_reference operator[](size_type n) const;
6276-
constexpr reference at(size_type n);
6277-
constexpr const_reference at(size_type n) const;
6277+
constexpr reference at(size_type n); // freestanding-deleted
6278+
constexpr const_reference at(size_type n) const; // freestanding-deleted
62786279
constexpr reference front();
62796280
constexpr const_reference front() const;
62806281
constexpr reference back();

source/lib-intro.tex

Lines changed: 72 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -901,29 +901,62 @@
901901
Unless otherwise specified,
902902
the requirements on freestanding items for a freestanding implementation
903903
are the same as the corresponding requirements for a hosted implementation,
904-
except that not all of the members of the namespaces are required to be present.
904+
except that not all of the members of those items are required to be present.
905+
906+
\pnum
907+
Function declarations and function template declarations
908+
followed by a comment that include \textit{freestanding-deleted} are
909+
\defnadjx{freestanding deleted}{functions}{function}.
910+
On freestanding implementations,
911+
it is \impldef{whether a freestanding deleted function is a deleted function}
912+
whether each entity introduced by a freestanding deleted function
913+
is a deleted function\iref{dcl.fct.def.delete} or
914+
whether the requirements are the same as
915+
the corresponding requirements for a hosted implementation.
905916
\begin{note}
906-
This implies that freestanding item enumerations have the same enumerators on
907-
freestanding implementations and hosted implementations.
908-
Furthermore, class types have the same members and
909-
class templates have the same deduction guides
910-
on freestanding implementations and hosted implementations.
917+
Deleted definitions reduce the chance of overload resolution silently changing
918+
when migrating from a freestanding implementation to a hosted implementation.
911919
\end{note}
920+
\begin{example}
921+
\begin{codeblock}
922+
double abs(double j); // freestanding-deleted
923+
\end{codeblock}
924+
\end{example}
912925

913926
\pnum
914927
\indextext{declaration!freestanding item}%
915-
A declaration in a header synopsis is a freestanding item if
928+
A declaration in a synopsis is a freestanding item if
916929
\begin{itemize}
917-
\item it is followed by a comment that includes \textit{freestanding}, or
918-
\item the header synopsis begins with a comment that includes \textit{all freestanding}.
930+
\item it is followed by a comment that includes \textit{freestanding},
931+
\item it is followed by a comment that includes \textit{freestanding-deleted}, or
932+
\item the header synopsis begins with a comment
933+
that includes \textit{freestanding} and
934+
the declaration is not followed by a comment that includes \textit{hosted}.
935+
\begin{note}
936+
Declarations followed by \textit{hosted} in freestanding headers are
937+
not freestanding items.
938+
As a result, looking up the name of such functions can vary
939+
between hosted and freestanding implementations.
940+
\end{note}
919941
\end{itemize}
942+
\begin{example}
943+
\begin{codeblock}
944+
// all freestanding
945+
namespace std {
946+
\end{codeblock}
947+
\end{example}
920948

921949
\pnum
922950
\indextext{entity!freestanding item}%
951+
\indextext{deduction guide!freestanding item}%
923952
\indextext{\idxgram{typedef-name}!freestanding item}%
924-
An entity or \grammarterm{typedef-name} is a freestanding item if it is:
953+
An entity, deduction guide, or \grammarterm{typedef-name} is
954+
a freestanding item if it is:
925955
\begin{itemize}
926956
\item introduced by a declaration that is a freestanding item,
957+
\item a member of a freestanding item other than a namespace,
958+
\item an enumerator of a freestanding item,
959+
\item a deduction guide of a freestanding item,
927960
\item an enclosing namespace of a freestanding item,
928961
\item a friend of a freestanding item,
929962
\item denoted by a \grammarterm{typedef-name} that is a freestanding item, or
@@ -934,35 +967,40 @@
934967
\indextext{macro!freestanding item}%
935968
A macro is a freestanding item if it is defined in a header synopsis and
936969
\begin{itemize}
937-
\item the definition is followed by a comment that includes \textit{freestanding}, or
938-
\item the header synopsis begins with a comment that includes \textit{all freestanding}.
970+
\item the definition is followed by a comment
971+
that includes \textit{freestanding}, or
972+
\item the header synopsis begins with a comment
973+
that includes \textit{freestanding} and
974+
the definition is not followed by a comment that includes \textit{hosted}.
939975
\end{itemize}
940-
941-
\pnum
942976
\begin{example}
943977
\begin{codeblock}
944978
#define NULL @\seebelow@ // freestanding
945979
\end{codeblock}
946980
\end{example}
947981

948-
\begin{example}
949-
\begin{codeblock}
950-
// all freestanding
951-
namespace std {
952-
\end{codeblock}
953-
\end{example}
954-
955982
\pnum
956-
Function declarations and function template declarations
957-
followed by a comment that include \textit{freestanding-deleted} are
958-
\defnadjx{freestanding deleted}{functions}{function}.
959-
On freestanding implementations,
960-
it is \impldef{whether a freestanding deleted function is a freestanding item or a deleted function}
961-
whether each function definition introduced by a freestanding deleted function
962-
is a freestanding item or a deleted function\iref{dcl.fct.def.delete}.
983+
\begin{note}
984+
Freestanding annotations follow some additional exposition conventions
985+
that do not impose any additional normative requirements.
986+
Header synopses that begin with a comment containing "all freestanding"
987+
contain no hosted items and no freestanding deleted functions.
988+
Header synopses that begin with a comment containing "mostly freestanding"
989+
contain at least one hosted item or freestanding deleted function.
990+
Classes and class templates followed by a comment
991+
containing "partially freestanding"
992+
contain at least one hosted item or freestanding deleted function.
993+
\end{note}
963994
\begin{example}
964995
\begin{codeblock}
965-
double abs(double j); // freestanding-deleted
996+
template<class T, size_t N> struct array; // partially freestanding
997+
template<class T, size_t N>
998+
struct array {
999+
constexpr reference operator[](size_type n);
1000+
constexpr const_reference operator[](size_type n) const;
1001+
constexpr reference at(size_type n); // freestanding-deleted
1002+
constexpr const_reference at(size_type n) const; // freestanding-deleted
1003+
};
9661004
\end{codeblock}
9671005
\end{example}
9681006

@@ -1485,14 +1523,18 @@
14851523
\ref{ratio} & Compile-time rational arithmetic & \tcode{<ratio>} \\ \rowsep
14861524
\ref{utility} & Utility components & \tcode{<utility>} \\ \rowsep
14871525
\ref{tuple} & Tuples & \tcode{<tuple>} \\ \rowsep
1526+
\ref{optional} & Optional objects & \tcode{<optional>} \\ \rowsep
1527+
\ref{variant} & Variants & \tcode{<variant>} \\ \rowsep
14881528
\ref{function.objects} & Function objects & \tcode{<functional>} \\ \rowsep
14891529
\ref{charconv} & Primitive numeric conversions & \tcode{<charconv>} \\ \rowsep
14901530
\ref{bit} & Bit manipulation & \tcode{<bit>} \\ \rowsep
1531+
\ref{string.view} & String view classes & \tcode{<string_view>} \\ \rowsep
14911532
\ref{string.classes} & String classes & \tcode{<string>} \\ \rowsep
14921533
\ref{c.strings} & Null-terminated sequence utilities & \tcode{<cstring>}, \tcode{<cwchar>} \\ \rowsep
1534+
\ref{array} & Class template \tcode{array} & \tcode{<array>} \\ \rowsep
14931535
\ref{iterators} & Iterators library & \tcode{<iterator>} \\ \rowsep
14941536
\ref{ranges} & Ranges library & \tcode{<ranges>} \\ \rowsep
1495-
\ref{algorithms} & Algorithms library & \tcode{<numeric>} \\ \rowsep
1537+
\ref{algorithms} & Algorithms library & \tcode{<algorithm>}, \tcode{<numeric>} \\ \rowsep
14961538
\ref{c.math} & Mathematical functions for floating-point types & \tcode{<cmath>} \\ \rowsep
14971539
\ref{atomics} & Atomics & \tcode{<atomic>} \\ \rowsep
14981540
\end{libsumtab}

source/strings.tex

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,13 @@
533533

534534
\indexheader{string_view}%
535535
\begin{codeblock}
536+
// mostly freestanding
536537
#include <compare> // see \ref{compare.syn}
537538

538539
namespace std {
539540
// \ref{string.view.template}, class template \tcode{basic_string_view}
540541
template<class charT, class traits = char_traits<charT>>
541-
class basic_string_view;
542+
class basic_string_view; // partially freestanding
542543

543544
template<class charT, class traits>
544545
constexpr bool ranges::@\libspec{enable_view}{basic_string_view}@<basic_string_view<charT, traits>> = true;
@@ -559,7 +560,7 @@
559560
template<class charT, class traits>
560561
basic_ostream<charT, traits>&
561562
operator<<(basic_ostream<charT, traits>& os,
562-
basic_string_view<charT, traits> str);
563+
basic_string_view<charT, traits> str); // hosted
563564

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

664665
// \ref{string.view.access}, element access
665666
constexpr const_reference operator[](size_type pos) const;
666-
constexpr const_reference at(size_type pos) const;
667+
constexpr const_reference at(size_type pos) const; // freestanding-deleted
667668
constexpr const_reference front() const;
668669
constexpr const_reference back() const;
669670
constexpr const_pointer data() const noexcept;
@@ -674,17 +675,22 @@
674675
constexpr void swap(basic_string_view& s) noexcept;
675676

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

679-
constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
681+
constexpr basic_string_view substr(size_type pos = 0,
682+
size_type n = npos) const; // freestanding-deleted
680683

681684
constexpr int compare(basic_string_view s) const noexcept;
682-
constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
685+
constexpr int compare(size_type pos1, size_type n1,
686+
basic_string_view s) const; // freestanding-deleted
683687
constexpr int compare(size_type pos1, size_type n1, basic_string_view s,
684-
size_type pos2, size_type n2) const;
688+
size_type pos2, size_type n2) const; // freestanding-deleted
685689
constexpr int compare(const charT* s) const;
686-
constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
687-
constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
690+
constexpr int compare(size_type pos1, size_type n1,
691+
const charT* s) const; // freestanding-deleted
692+
constexpr int compare(size_type pos1, size_type n1, const charT* s,
693+
size_type n2) const; // freestanding-deleted
688694

689695
constexpr bool starts_with(basic_string_view x) const noexcept;
690696
constexpr bool starts_with(charT x) const noexcept;
@@ -1311,9 +1317,12 @@
13111317
\end{itemdecl}
13121318

13131319
\begin{itemdescr}
1320+
\pnum
1321+
Let \tcode{rlen} be the smaller of \tcode{size()} and \tcode{x.size()}.
1322+
13141323
\pnum
13151324
\effects
1316-
Equivalent to: \tcode{return substr(0, x.size()) == x;}
1325+
Equivalent to: \tcode{return basic_string_view(data(), rlen) == x;}
13171326
\end{itemdescr}
13181327

13191328
\indexlibrarymember{starts_with}{basic_string_view}%
@@ -1344,11 +1353,14 @@
13441353
\end{itemdecl}
13451354

13461355
\begin{itemdescr}
1356+
\pnum
1357+
Let \tcode{rlen} be the smaller of \tcode{size()} and \tcode{x.size()}.
1358+
13471359
\pnum
13481360
\effects
13491361
Equivalent to:
13501362
\begin{codeblock}
1351-
return size() >= x.size() && compare(size() - x.size(), npos, x) == 0;
1363+
return basic_string_view(data() + (size() - rlen), rlen) == x;
13521364
\end{codeblock}
13531365
\end{itemdescr}
13541366

@@ -1439,7 +1451,7 @@
14391451
\item
14401452
\tcode{xpos + str.size() <= size()}
14411453
\item
1442-
\tcode{traits::eq(at(xpos + I), str.at(I))} for all elements \tcode{I} of the string referenced by \tcode{str}.
1454+
\tcode{traits::eq(data_[xpos + I], str[I])} for all elements \tcode{I} of the string referenced by \tcode{str}.
14431455
\end{itemize}
14441456

14451457
\pnum
@@ -1466,7 +1478,7 @@
14661478
\item
14671479
\tcode{xpos + str.size() <= size()}
14681480
\item
1469-
\tcode{traits::eq(at(xpos + I), str.at(I))} for all elements \tcode{I} of the string referenced by \tcode{str}.
1481+
\tcode{traits::eq(data_[xpos + I], str[I])} for all elements \tcode{I} of the string referenced by \tcode{str}.
14701482
\end{itemize}
14711483

14721484
\pnum
@@ -1493,7 +1505,7 @@
14931505
\item
14941506
\tcode{xpos < size()}
14951507
\item
1496-
\tcode{traits::eq(at(xpos), str.at(I))} for some element \tcode{I} of the string referenced by \tcode{str}.
1508+
\tcode{traits::eq(data_[xpos], str[I])} for some element \tcode{I} of the string referenced by \tcode{str}.
14971509
\end{itemize}
14981510

14991511
\pnum
@@ -1520,7 +1532,7 @@
15201532
\item
15211533
\tcode{xpos < size()}
15221534
\item
1523-
\tcode{traits::eq(at(xpos), str.at(I))} for some element \tcode{I} of the string referenced by \tcode{str}.
1535+
\tcode{traits::eq(data_[xpos], str[I])} for some element \tcode{I} of the string referenced by \tcode{str}.
15241536
\end{itemize}
15251537

15261538
\pnum
@@ -1547,7 +1559,7 @@
15471559
\item
15481560
\tcode{xpos < size()}
15491561
\item
1550-
\tcode{traits::eq(at(xpos), str.at(I))} for no element \tcode{I} of the string referenced by \tcode{str}.
1562+
\tcode{traits::eq(data_[xpos], str[I])} for no element \tcode{I} of the string referenced by \tcode{str}.
15511563
\end{itemize}
15521564

15531565
\pnum
@@ -1573,7 +1585,7 @@
15731585
\item
15741586
\tcode{xpos < size()}
15751587
\item
1576-
\tcode{traits::eq(at(xpos), str.at(I))} for no element \tcode{I} of the string referenced by \tcode{str}.
1588+
\tcode{traits::eq(data_[xpos], str[I])} for no element \tcode{I} of the string referenced by \tcode{str}.
15771589
\end{itemize}
15781590

15791591
\pnum

source/support.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@
635635
#define @\defnlibxname{cpp_lib_format_ranges}@ 202207L // also in \libheader{format}
636636
#define @\defnlibxname{cpp_lib_formatters}@ 202302L // also in \libheader{stacktrace}, \libheader{thread}
637637
#define @\defnlibxname{cpp_lib_forward_like}@ 202207L // freestanding, also in \libheader{utility}
638+
#define @\defnlibxname{cpp_lib_freestanding_algorithm}@ 202311L // freestanding, also in \libheader{algorithm}
639+
#define @\defnlibxname{cpp_lib_freestanding_array}@ 202311L // freestanding, also in \libheader{array}
638640
#define @\defnlibxname{cpp_lib_freestanding_char_traits}@ 202306L // freestanding, also in \libheader{string}
639641
#define @\defnlibxname{cpp_lib_freestanding_charconv}@ 202306L // freestanding, also in \libheader{charconv}
640642
#define @\defnlibxname{cpp_lib_freestanding_cstdlib}@ 202306L // freestanding, also in \libheader{cstdlib}, \libheader{cmath}
@@ -647,10 +649,13 @@
647649
#define @\defnlibxname{cpp_lib_freestanding_iterator}@ 202306L // freestanding, also in \libheader{iterator}
648650
#define @\defnlibxname{cpp_lib_freestanding_memory}@ 202306L // freestanding, also in \libheader{memory}
649651
#define @\defnlibxname{cpp_lib_freestanding_operator_new}@ @\seebelow@ // freestanding, also in \libheader{new}
652+
#define @\defnlibxname{cpp_lib_freestanding_optional}@ 202311L // freestanding, also in \libheader{optional}
650653
#define @\defnlibxname{cpp_lib_freestanding_ranges}@ 202306L // freestanding, also in \libheader{ranges}
651654
#define @\defnlibxname{cpp_lib_freestanding_ratio}@ 202306L // freestanding, also in \libheader{ratio}
655+
#define @\defnlibxname{cpp_lib_freestanding_string_view}@ 202311L // freestanding, also in \libheader{string_view}
652656
#define @\defnlibxname{cpp_lib_freestanding_tuple}@ 202306L // freestanding, also in \libheader{tuple}
653657
#define @\defnlibxname{cpp_lib_freestanding_utility}@ 202306L // freestanding, also in \libheader{utility}
658+
#define @\defnlibxname{cpp_lib_freestanding_variant}@ 202311L // freestanding, also in \libheader{variant}
654659
#define @\defnlibxname{cpp_lib_fstream_native_handle}@ 202306L // also in \libheader{fstream}
655660
#define @\defnlibxname{cpp_lib_function_ref}@ 202306L // also in \libheader{functional}
656661
#define @\defnlibxname{cpp_lib_gcd_lcm}@ 201606L // also in \libheader{numeric}

0 commit comments

Comments
 (0)