Skip to content

Commit a129fc3

Browse files
committed
test SFINAE variants
#test
1 parent 2fb4134 commit a129fc3

File tree

4 files changed

+1009
-0
lines changed

4 files changed

+1009
-0
lines changed
Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
= Reference
2+
:mrdocs:
3+
4+
[#index]
5+
== Global namespace
6+
7+
8+
=== Types
9+
10+
[cols=2]
11+
|===
12+
| Name | Description
13+
14+
| <<A-09,`A`>>
15+
| The partial specialization of A is enabled via a template parameter
16+
17+
18+
19+
| <<A-02,`A&lt;T, void&gt;`>>
20+
| Specialization for floating point types
21+
22+
23+
24+
|===
25+
=== Functions
26+
27+
[cols=2]
28+
|===
29+
| Name | Description
30+
31+
| <<f1,`f1`>>
32+
| Enabled via return type
33+
34+
35+
36+
| <<f10,`f10`>>
37+
| Enabled via type template parameter
38+
39+
40+
41+
| <<f2,`f2`>>
42+
| Enabling a specified return type
43+
44+
45+
46+
| <<f3,`f3`>>
47+
| Enabling a specified return type in another namespace
48+
49+
50+
51+
| <<f4,`f4`>>
52+
| Enabled via return type with std&colon;&colon;enable&lowbar;if
53+
54+
55+
56+
| <<f5,`f5`>>
57+
| Enabled via a non&hyphen;type template parameter with helper
58+
59+
60+
61+
| <<f6,`f6`>>
62+
| Enabled via a non&hyphen;type template parameter without helper
63+
64+
65+
66+
| <<f7,`f7`>>
67+
| Enabled via a non&hyphen;type template parameter using int instead of bool
68+
69+
70+
71+
| <<f8,`f8`>>
72+
| Enabled via parameter without helper
73+
74+
75+
76+
| <<f9,`f9`>>
77+
| Enabled via parameter with helper
78+
79+
80+
81+
|===
82+
83+
[#A-09]
84+
== A
85+
86+
87+
The partial specialization of A is enabled via a template parameter
88+
89+
90+
91+
=== Synopsis
92+
93+
94+
Declared in `&lt;sfinae&period;cpp&gt;`
95+
96+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
97+
----
98+
template&lt;
99+
class T,
100+
class Enable = void&gt;
101+
class A;
102+
----
103+
104+
105+
106+
107+
[#A-02]
108+
== A&lt;T, void&gt;
109+
110+
111+
Specialization for floating point types
112+
113+
114+
115+
=== Synopsis
116+
117+
118+
Declared in `&lt;sfinae&period;cpp&gt;`
119+
120+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
121+
----
122+
template&lt;class T&gt;
123+
class <<A-09,A>>&lt;T, void&gt;;
124+
----
125+
126+
127+
128+
129+
[#f1]
130+
== f1
131+
132+
133+
Enabled via return type
134+
135+
136+
137+
=== Synopsis
138+
139+
140+
Declared in `&lt;sfinae&period;cpp&gt;`
141+
142+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
143+
----
144+
template&lt;class T&gt;
145+
T
146+
f1(T value);
147+
----
148+
149+
[#f10]
150+
== f10
151+
152+
153+
Enabled via type template parameter
154+
155+
156+
157+
=== Synopsis
158+
159+
160+
Declared in `&lt;sfinae&period;cpp&gt;`
161+
162+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
163+
----
164+
template&lt;
165+
class T,
166+
typename = void&gt;
167+
void
168+
f10(T* t);
169+
----
170+
171+
=== Description
172+
173+
174+
This pattern should not be used because the function signature is unmodified and therefore only supports one overload&period;
175+
176+
It&apos;s a common mistake is to declare two function templates that differ only in their default template arguments&period;
177+
178+
This does not work because the declarations are treated as redeclarations of the same function template (default template arguments are not accounted for in function template equivalence)&period;
179+
180+
181+
182+
[#f2]
183+
== f2
184+
185+
186+
Enabling a specified return type
187+
188+
189+
190+
=== Synopsis
191+
192+
193+
Declared in `&lt;sfinae&period;cpp&gt;`
194+
195+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
196+
----
197+
template&lt;class T&gt;
198+
int
199+
f2(T value);
200+
----
201+
202+
[#f3]
203+
== f3
204+
205+
206+
Enabling a specified return type in another namespace
207+
208+
209+
210+
=== Synopsis
211+
212+
213+
Declared in `&lt;sfinae&period;cpp&gt;`
214+
215+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
216+
----
217+
template&lt;class T&gt;
218+
std::size&lowbar;t
219+
f3(T value);
220+
----
221+
222+
[#f4]
223+
== f4
224+
225+
226+
Enabled via return type with std&colon;&colon;enable&lowbar;if
227+
228+
229+
230+
=== Synopsis
231+
232+
233+
Declared in `&lt;sfinae&period;cpp&gt;`
234+
235+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
236+
----
237+
template&lt;class T&gt;
238+
T
239+
f4(T value);
240+
----
241+
242+
[#f5]
243+
== f5
244+
245+
246+
Enabled via a non&hyphen;type template parameter with helper
247+
248+
249+
250+
=== Synopsis
251+
252+
253+
Declared in `&lt;sfinae&period;cpp&gt;`
254+
255+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
256+
----
257+
template&lt;
258+
class T,
259+
bool = true&gt;
260+
T
261+
f5(T value);
262+
----
263+
264+
[#f6]
265+
== f6
266+
267+
268+
Enabled via a non&hyphen;type template parameter without helper
269+
270+
271+
272+
=== Synopsis
273+
274+
275+
Declared in `&lt;sfinae&period;cpp&gt;`
276+
277+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
278+
----
279+
template&lt;
280+
class T,
281+
bool = true&gt;
282+
T
283+
f6(T value);
284+
----
285+
286+
[#f7]
287+
== f7
288+
289+
290+
Enabled via a non&hyphen;type template parameter using int instead of bool
291+
292+
293+
294+
=== Synopsis
295+
296+
297+
Declared in `&lt;sfinae&period;cpp&gt;`
298+
299+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
300+
----
301+
template&lt;
302+
class T,
303+
int = 0&gt;
304+
void
305+
f7(T value);
306+
----
307+
308+
[#f8]
309+
== f8
310+
311+
312+
Enabled via parameter without helper
313+
314+
315+
316+
=== Synopsis
317+
318+
319+
Declared in `&lt;sfinae&period;cpp&gt;`
320+
321+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
322+
----
323+
template&lt;class T&gt;
324+
T
325+
f8(
326+
T value,
327+
void* = 0);
328+
----
329+
330+
[#f9]
331+
== f9
332+
333+
334+
Enabled via parameter with helper
335+
336+
337+
338+
=== Synopsis
339+
340+
341+
Declared in `&lt;sfinae&period;cpp&gt;`
342+
343+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
344+
----
345+
template&lt;class T&gt;
346+
T
347+
f9(
348+
T value,
349+
void* = 0);
350+
----
351+
352+
353+
354+
[.small]#Created with https://www.mrdocs.com[MrDocs]#

0 commit comments

Comments
 (0)