Skip to content

Commit 8f8dd56

Browse files
authored
Merge pull request #38 from nliber/issue260
Rule of Zero for Common by-value semantics classes (Gitlab issue 260)
2 parents 87b073c + a30cd72 commit 8f8dd56

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

latex/glossary.tex

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,26 @@
445445
)}
446446
}
447447

448+
\newglossaryentry{rule-of-five}
449+
{
450+
name={rule of five},
451+
description={For a given class, if at least one of the
452+
copy constructor, move constructor, copy assignment operator, move assignment operator or destructor
453+
is explicitly declared,
454+
all of them should be explicity declared
455+
}
456+
}
457+
458+
\newglossaryentry{rule-of-zero}
459+
{
460+
name={rule of zero},
461+
description={For a given class, if the
462+
copy constructor, move constructor, copy assignment operator, move assignment operator and destructor
463+
would all be inlined, public and defaulted,
464+
none of them should be explicity declared
465+
}
466+
}
467+
448468
\newglossaryentry{smcp}
449469
{
450470
name={SMCP},

latex/headers/common-byval.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@ class T {
1919
...
2020

2121
public:
22-
T(const T &rhs) = default;
22+
// If any of the following five special member functions are not
23+
// public, inline or defaulted, then all five of them should be
24+
// explicitly declared (see rule of five).
25+
// Otherwise, none of them should be explicitly declared
26+
// (see rule of zero).
2327

24-
T(T &&rhs) = default;
28+
// T(const T &rhs);
2529

26-
T &operator=(const T &rhs) = default;
30+
// T(T &&rhs);
2731

28-
T &operator=(T &&rhs) = default;
32+
// T &operator=(const T &rhs);
2933

30-
~T() = default;
34+
// T &operator=(T &&rhs);
35+
36+
// ~T();
3137

3238
...
3339

latex/programming_interface.tex

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,39 +187,39 @@ \subsection{Common by-value semantics}
187187

188188
Some \gls{sycl-runtime} classes will have additional behavior associated with copy, movement, assignment or destruction semantics. If these are specified they are in addition to those specified above unless stated otherwise.
189189

190-
Each of the runtime classes mentioned above must provide a common interface of special member functions in order to fulfil the copy, move, destruction requirements and hidden friend functions to satisfy the equality requirements.
190+
Each of the runtime classes mentioned above must provide a common interface of special member functions and member functions in order to fulfil the copy, move, destruction and equality requirements, following the \gls{rule-of-five} and the \gls{rule-of-zero}.
191191

192192
These common special member functions and hidden friend functions are described in Tables~\ref{table.specialmembers.common.byval} and \ref{table.hiddenfriends.common.byval} respectively.
193193

194194
\lstinputlistingSkipLicense{headers/common-byval.h}
195195

196-
\startTable{Special member function}
196+
\startTable{Special member function \textit{(see \gls{rule-of-five} \& \gls{rule-of-zero})}}
197197
\addFootNotes{Common special member functions for by-value semantics}
198198
{table.specialmembers.common.byval}
199199
\addRow
200-
{T(const T \&rhs) = default}
200+
{T(const T \&rhs);}
201201
{
202-
Default copy constructor.
202+
Copy constructor.
203203
}
204204
\addRow
205-
{T(T \&\&rhs) = default}
205+
{T(T \&\&rhs);}
206206
{
207-
Default move constructor.
207+
Move constructor.
208208
}
209209
\addRow
210-
{T \&operator=(const T \&rhs) = default}
210+
{T \&operator=(const T \&rhs);}
211211
{
212-
Default copy assignment operator.
212+
Copy assignment operator.
213213
}
214214
\addRow
215-
{T \&operator=(T \&\&rhs) = default}
215+
{T \&operator=(T \&\&rhs);}
216216
{
217-
Default move assignment operator.
217+
Move assignment operator.
218218
}
219219
\addRow
220-
{\~T() = default}
220+
{\~T();}
221221
{
222-
Default destructor.
222+
Destructor.
223223
}
224224
\completeTable
225225

0 commit comments

Comments
 (0)