Skip to content

Commit 54fa5df

Browse files
committed
Merge Library Fundamentals V1 into Library Fundamentals V2 according to the instructions in N4521
per LWG Motion 9 at the 2015-05 Lenexa meeting. http://wiki.edg.com/twiki/bin/view/Wg21lenexa/StrawPolls
2 parents 5b69ee0 + 5a7a1bd commit 54fa5df

14 files changed

+15116
-1318
lines changed

algorithms.html

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<cxx-clause id="algorithms">
2+
<h1>Algorithms library</h1>
3+
4+
<cxx-section id="header.algorithm.synop">
5+
<h1>Header <code>&lt;experimental/algorithm></code> synopsis</h1>
6+
7+
<pre><code>#include &lt;algorithm>
8+
9+
namespace std {
10+
namespace experimental {
11+
inline namespace fundamentals_v2 {
12+
13+
template&lt;class ForwardIterator, class Searcher&gt;
14+
ForwardIterator search(ForwardIterator first, ForwardIterator last,
15+
const Searcher&amp; searcher);
16+
17+
template&lt;class PopulationIterator, class SampleIterator,
18+
class Distance, class UniformRandomNumberGenerator>
19+
SampleIterator sample(PopulationIterator first, PopulationIterator last,
20+
SampleIterator out, Distance n,
21+
UniformRandomNumberGenerator&amp;&amp; g);
22+
23+
} // namespace fundamentals_v2
24+
} // namespace experimental
25+
} // namespace std</code></pre>
26+
27+
</cxx-section>
28+
29+
<cxx-section id="alg.search">
30+
<h1>Search</h1>
31+
32+
<cxx-function>
33+
<cxx-signature>template&lt;class ForwardIterator, class Searcher&gt;
34+
ForwardIterator search(ForwardIterator first, ForwardIterator last,
35+
const Searcher&amp; searcher);</cxx-signature>
36+
37+
<cxx-effects>Equivalent to <code>return searcher(first, last)</code>.</cxx-effects>
38+
<cxx-remarks><code>Searcher</code> need not meet the <code>CopyConstructible</code> requirements.</cxx-remarks>
39+
</cxx-function>
40+
</cxx-section>
41+
42+
<cxx-section id="alg.random.sample">
43+
<h1>Shuffling and sampling</h1>
44+
45+
<cxx-function>
46+
<cxx-signature class="formatted">template&lt;class PopulationIterator, class SampleIterator,
47+
class Distance, class UniformRandomNumberGenerator>
48+
SampleIterator sample(PopulationIterator first, PopulationIterator last,
49+
SampleIterator out, Distance n,
50+
UniformRandomNumberGenerator&amp;&amp; g);</cxx-signature>
51+
52+
53+
<cxx-requires>
54+
<ul>
55+
<li><code>PopulationIterator</code> shall meet the requirements of an <code>InputIterator</code> type.</li>
56+
<li><code>SampleIterator</code> shall meet the requirements of an <code>OutputIterator</code> type.</li>
57+
<li><code>SampleIterator</code> shall meet the additional requirements of a <code>RandomAccessIterator</code> type
58+
unless <code>PopulationIterator</code> meets the additional requirements of a <code>ForwardIterator</code> type.</li>
59+
<li><code>PopulationIterator</code>'s value type shall be writable to <code>out</code>.</li>
60+
<li><code>Distance</code> shall be an integer type.</li>
61+
<li><code>UniformRandomNumberGenerator</code> shall meet the requirements of a uniform random number generator type (<cxx-ref in="cxx" to="rand.req.urng"></cxx-ref>)
62+
whose return type is convertible to <code>Distance</code>.</li>
63+
<li><code>out</code> shall not be in the range <cxx-range begin="first" end="last"></cxx-range>.</li>
64+
</ul>
65+
</cxx-requires>
66+
<cxx-effects>Copies <code>min(last−first, n)</code> elements (the <dfn>sample</dfn>)
67+
from <cxx-range begin="first" end="last"></cxx-range> (the <dfn>population</dfn>) to <code>out</code>
68+
such that each possible sample has equal probability of appearance.
69+
<cxx-note>Algorithms that obtain such effects include <cxx-term>selection sampling</cxx-term> and <cxx-term>reservoir sampling</cxx-term>.</cxx-note></cxx-effects>
70+
<cxx-returns>The end of the resulting sample range.</cxx-returns>
71+
<cxx-complexity>O(<code>last - first</code>).</cxx-complexity>
72+
<cxx-remarks>
73+
<ul>
74+
<li>Stable if and only if <code>PopulationIterator</code> meets the requirements of a <code>ForwardIterator</code> type.</li>
75+
<li>To the extent that the implementation of this function makes use of random numbers, the object <code>g</code> shall serve as the implementation’s source of randomness.</li>
76+
</ul>
77+
</cxx-remarks>
78+
</cxx-function>
79+
</cxx-section>
80+
</cxx-clause>

any.html

+284
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
<cxx-clause id="any">
2+
<h1>Class <code>any</code></h1>
3+
4+
<p>
5+
This section describes components that C++ programs may use to perform operations on objects of a discriminated type.
6+
</p>
7+
8+
<p>
9+
<cxx-note>The discriminated type may contain values of different types but does not attempt conversion between them,
10+
i.e. <code>5</code> is held strictly as an <code>int</code> and is not implicitly convertible either to <code>&quot;5&quot;</code> or to <code>5.0</code>.
11+
This indifference to interpretation but awareness of type effectively allows safe, generic containers of single values, with no scope for surprises from ambiguous conversions.</cxx-note>
12+
</p>
13+
14+
<cxx-section id="any.synop">
15+
<h1>Header &lt;experimental/any&gt; synopsis</h1>
16+
17+
<pre><code>namespace std {
18+
namespace experimental {
19+
inline namespace fundamentals_v2 {
20+
21+
class bad_any_cast : public bad_cast
22+
{
23+
public:
24+
virtual const char* what() const noexcept;
25+
};
26+
27+
class any
28+
{
29+
public:
30+
<cxx-ref insynopsis="" to="any.cons"></cxx-ref>
31+
any() noexcept;
32+
33+
any(const any&amp; other);
34+
any(any&amp;&amp; other) noexcept;
35+
36+
template &lt;class ValueType&gt;
37+
any(ValueType&amp;&amp; value);
38+
39+
~any();
40+
41+
<cxx-ref insynopsis="" to="any.assign"></cxx-ref>
42+
any&amp; operator=(const any&amp; rhs);
43+
any&amp; operator=(any&amp;&amp; rhs) noexcept;
44+
45+
template &lt;class ValueType&gt;
46+
any&amp; operator=(ValueType&amp;&amp; rhs);
47+
48+
<cxx-ref insynopsis="" to="any.modifiers"></cxx-ref>
49+
void clear() noexcept;
50+
void swap(any&amp; rhs) noexcept;
51+
52+
<cxx-ref insynopsis="" to="any.observers"></cxx-ref>
53+
bool empty() const noexcept;
54+
const type_info&amp; type() const noexcept;
55+
};
56+
57+
<cxx-ref insynopsis="" to="any.nonmembers"></cxx-ref>
58+
void swap(any&amp; x, any&amp; y) noexcept;
59+
60+
template&lt;class ValueType&gt;
61+
ValueType any_cast(const any&amp; operand);
62+
template&lt;class ValueType&gt;
63+
ValueType any_cast(any&amp; operand);
64+
template&lt;class ValueType&gt;
65+
ValueType any_cast(any&amp;&amp; operand);
66+
67+
template&lt;class ValueType&gt;
68+
const ValueType* any_cast(const any* operand) noexcept;
69+
template&lt;class ValueType&gt;
70+
ValueType* any_cast(any* operand) noexcept;
71+
72+
} // namespace fundamentals_v2
73+
} // namespace experimental
74+
} // namespace std</code></pre>
75+
</cxx-section>
76+
77+
<cxx-section id="any.bad_any_cast">
78+
<h1>Class <code>bad_any_cast</code></h1>
79+
<p>
80+
Objects of type <code>bad_any_cast</code> are thrown by a failed <code> any_cast</code>.
81+
</p>
82+
</cxx-section>
83+
84+
<cxx-section id="any.class">
85+
<h1>Class <code>any</code></h1>
86+
87+
<p>
88+
An object of class <code>any</code> stores an instance of any type that satisfies the constructor requirements or is empty,
89+
and this is referred to as the <dfn>state</dfn> of the class <code>any</code> object.
90+
The stored instance is called the <dfn>contained object</dfn>.
91+
Two states are equivalent if they are either both empty or if both are not empty and if the contained objects are equivalent.
92+
</p>
93+
94+
<p>
95+
The non-member <code>any_cast</code> functions provide type-safe access to the contained object.
96+
</p>
97+
98+
<p>
99+
Implementations should avoid the use of dynamically allocated memory for a small contained object.
100+
<cxx-example class="inline">where the object constructed is holding only an int.</cxx-example>
101+
Such small-object optimization shall only be applied to types <code>T</code> for which
102+
<code>is_nothrow_move_constructible_v&lt;T&gt;</code> is true.
103+
</p>
104+
105+
<cxx-section id="any.cons">
106+
<h1><code>any</code> construct/destruct</h1>
107+
108+
<cxx-function>
109+
<cxx-signature>any() noexcept;</cxx-signature>
110+
111+
<cxx-postconditions><code>this-&gt;empty()</code></cxx-postconditions>
112+
</cxx-function>
113+
114+
<cxx-function>
115+
<cxx-signature>any(const any&amp; other);</cxx-signature>
116+
117+
<cxx-effects>Constructs an object of type <code>any</code> with an equivalent state as <code>other</code>.</cxx-effects>
118+
<cxx-throws>Any exceptions arising from calling the selected constructor of the contained object.</cxx-throws>
119+
</cxx-function>
120+
121+
<cxx-function>
122+
<cxx-signature>any(any&amp;&amp; other) noexcept;</cxx-signature>
123+
124+
<cxx-effects>Constructs an object of type <code>any</code> with a state equivalent to the original state of <code>other</code>.</cxx-effects>
125+
<cxx-postconditions><code>other</code> is left in a valid but otherwise unspecified state.</cxx-postconditions>
126+
</cxx-function>
127+
128+
<cxx-function>
129+
<cxx-signature>template&lt;class ValueType&gt;
130+
any(ValueType&amp;&amp; value);</cxx-signature>
131+
132+
<p>Let <code>T</code> be equal to <code>decay_t&lt;ValueType&gt;</code>.</p>
133+
<cxx-requires><code>T</code> shall satisfy the <code>CopyConstructible</code> requirements.
134+
If <code>is_copy_constructible_v&lt;T&gt;</code> is false, the program is ill-formed.</cxx-requires>
135+
<cxx-effects>Constructs an object of type <code>any</code> that contains an object of type <code>T</code> direct-initialized with <code>std::forward&lt;ValueType&gt;(value)</code>.</cxx-effects>
136+
<cxx-remarks>This constructor shall not participate in overload resolution if <code>decay_t&lt;ValueType&gt;</code> is the same type as <code>any</code>.</cxx-remarks>
137+
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
138+
</cxx-function>
139+
140+
<cxx-function>
141+
<cxx-signature>~any();</cxx-signature>
142+
143+
<cxx-effects><code>clear()</code>.</cxx-effects>
144+
</cxx-function>
145+
</cxx-section>
146+
147+
<cxx-section id="any.assign">
148+
<h1><code>any</code> assignments</h1>
149+
150+
<cxx-function>
151+
<cxx-signature>any&amp; operator=(const any&amp; rhs);</cxx-signature>
152+
153+
<cxx-effects><code>any(rhs).swap(*this)</code>.
154+
No effects if an exception is thrown.</cxx-effects>
155+
<cxx-returns><code>*this</code></cxx-returns>
156+
<cxx-throws>Any exceptions arising from the copy constructor of the contained object.</cxx-throws>
157+
</cxx-function>
158+
159+
<cxx-function>
160+
<cxx-signature>any&amp; operator=(any&amp;&amp; rhs) noexcept;</cxx-signature>
161+
162+
<cxx-effects><code>any(std::move(rhs)).swap(*this)</code>.</cxx-effects>
163+
<cxx-returns><code>*this</code></cxx-returns>
164+
<cxx-postconditions>The state of <code>*this</code> is equivalent to the original state of <code>rhs</code>
165+
and <code>rhs</code> is left in a valid but otherwise unspecified state.</cxx-postconditions>
166+
</cxx-function>
167+
168+
<cxx-function>
169+
<cxx-signature>template&lt;class ValueType&gt;
170+
any&amp; operator=(ValueType&amp;&amp; rhs);</cxx-signature>
171+
172+
<p>Let <code>T</code> be equal to <code>decay_t&lt;ValueType&gt;</code>.</p>
173+
<cxx-requires><code>T</code> shall satisfy the <code>CopyConstructible</code> requirements.
174+
If <code>is_copy_constructible_v&lt;T&gt;</code> is false, the program is ill-formed.</cxx-requires>
175+
<cxx-effects>Constructs an object <code>tmp</code> of type <code>any</code> that contains an object of type <code>T</code> direct-initialized with <code>std::forward&lt;ValueType&gt;(rhs)</code>, and <code>tmp.swap(*this)</code>.
176+
No effects if an exception is thrown.</cxx-effects>
177+
<cxx-returns><code>*this</code></cxx-returns>
178+
<cxx-remarks> This operator shall not participate in overload resolution if <code>decay_t&lt;ValueType&gt;</code> is the same type as <code>any</code>.</cxx-remarks>
179+
<cxx-throws>Any exception thrown by the selected constructor of <code>T</code>.</cxx-throws>
180+
</cxx-function>
181+
</cxx-section>
182+
183+
<cxx-section id="any.modifiers">
184+
<h1><code>any</code> modifiers</h1>
185+
186+
<cxx-function>
187+
<cxx-signature>void clear() noexcept;</cxx-signature>
188+
189+
<cxx-effects>If not empty, destroys the contained object.</cxx-effects>
190+
<cxx-postconditions><code>empty() == true</code>.</cxx-postconditions>
191+
</cxx-function>
192+
193+
<cxx-function>
194+
<cxx-signature>void swap(any&amp; rhs) noexcept;</cxx-signature>
195+
196+
<cxx-effects>Exchange the states of <code>*this</code> and <code> rhs</code>.</cxx-effects>
197+
</cxx-function>
198+
</cxx-section>
199+
200+
<cxx-section id="any.observers">
201+
<h1><code>any</code> observers</h1>
202+
203+
<cxx-function>
204+
<cxx-signature>bool empty() const noexcept;</cxx-signature>
205+
206+
<cxx-returns><code>true</code> if <code>*this</code> has no contained object, otherwise <code> false</code>.</cxx-returns>
207+
</cxx-function>
208+
209+
<cxx-function>
210+
<cxx-signature>const type_info&amp; type() const noexcept;</cxx-signature>
211+
212+
<cxx-returns>If <code>*this</code> has a contained object of type T, <code>typeid(T)</code>;
213+
otherwise <code>typeid(void)</code>.</cxx-returns>
214+
<p><cxx-note>Useful for querying against types known either at compile time or only at runtime.</cxx-note></p>
215+
</cxx-function>
216+
</cxx-section>
217+
</cxx-section>
218+
219+
<cxx-section id="any.nonmembers">
220+
<h1><a name="Non-member">Non-member</a> functions</h1>
221+
222+
<cxx-function>
223+
<cxx-signature>void swap(any&amp; x, any&amp; y) noexcept;</cxx-signature>
224+
225+
<cxx-effects><code>x.swap(y)</code>.</cxx-effects>
226+
</cxx-function>
227+
228+
<cxx-function>
229+
<cxx-signature>template&lt;class ValueType&gt;
230+
ValueType any_cast(const any&amp; operand);</cxx-signature>
231+
<cxx-signature>template&lt;class ValueType&gt;
232+
ValueType any_cast(any&amp; operand);</cxx-signature>
233+
<cxx-signature>template&lt;class ValueType&gt;
234+
ValueType any_cast(any&amp;&amp; operand);</cxx-signature>
235+
236+
<cxx-requires><code>is_reference_v&lt;ValueType&gt;</code> is true or <code>is_copy_constructible_v&lt;ValueType&gt;</code> is true.
237+
Otherwise the program is ill-formed.</cxx-requires>
238+
<cxx-returns>For the first form, <code>*any_cast&lt;add_const_t&lt;remove_reference_t&lt;ValueType&gt;&gt;&gt;(&amp;operand)</code>.
239+
For the second and third forms, <code>*any_cast&lt;remove_reference_t&lt;ValueType&gt;&gt;(&amp;operand)</code>.</cxx-returns>
240+
<cxx-throws><code>bad_any_cast</code> if <code>operand.type() != typeid(remove_reference_t&lt;ValueType&gt;)</code>.</cxx-throws>
241+
<cxx-example>
242+
<pre><code>any x(5); // x holds int
243+
assert(any_cast&lt;int&gt;(x) == 5); // cast to value
244+
any_cast&lt;int&amp;&gt;(x) = 10; // cast to reference
245+
assert(any_cast&lt;int&gt;(x) == 10);
246+
247+
x = &quot;Meow&quot;; // x holds const char*
248+
assert(strcmp(any_cast&lt;const char*&gt;(x), &quot;Meow&quot;) == 0);
249+
any_cast&lt;const char*&amp;&gt;(x) = &quot;Harry&quot;;
250+
assert(strcmp(any_cast&lt;const char*&gt;(x), &quot;Harry&quot;) == 0);
251+
252+
x = string(&quot;Meow&quot;); // x holds string
253+
string s, s2(&quot;Jane&quot;);
254+
s = move(any_cast&lt;string&amp;&gt;(x)); // move from any
255+
assert(s == &quot;Meow&quot;);
256+
any_cast&lt;string&amp;&gt;(x) = move(s2); // move to any
257+
assert(any_cast&lt;const string&amp;&gt;(x) == &quot;Jane&quot;);
258+
259+
string cat(&quot;Meow&quot;);
260+
const any y(cat); // const y holds string
261+
assert(any_cast&lt;const string&amp;&gt;(y) == cat);
262+
263+
any_cast&lt;string&amp;&gt;(y); // error; cannot
264+
// any_cast away const</code></pre>
265+
</cxx-example>
266+
</cxx-function>
267+
268+
<cxx-function>
269+
<cxx-signature>template&lt;class ValueType&gt;
270+
const ValueType* any_cast(const any* operand) noexcept;</cxx-signature>
271+
<cxx-signature>template&lt;class ValueType&gt;
272+
ValueType* any_cast(any* operand) noexcept;</cxx-signature>
273+
274+
<cxx-returns>If <code>operand != nullptr &amp;&amp; <w-br></w-br>operand-&gt;type() == typeid(ValueType)</code>,
275+
a pointer to the object contained by <code>operand</code>,
276+
otherwise <code>nullptr</code>.</cxx-returns>
277+
<cxx-example>
278+
<pre><code>bool is_string(const any&amp; operand) {
279+
return any_cast&lt;string&gt;(&amp;operand) != nullptr;
280+
}</code></pre>
281+
</cxx-example>
282+
</cxx-function>
283+
</cxx-section>
284+
</cxx-clause>

0 commit comments

Comments
 (0)