Skip to content

Commit 83f6cab

Browse files
N-Dekkerdzenanz
authored andcommitted
STYLE: Remove TimeStamp default-constructor, assignment (Rule of Zero)
Allowed the compiler to generate the default-constructor and assignment operator of `TimeStamp` implicitly, followed C++ Core Guidelines, August 19, 2021: "If you can avoid defining default operations, do" http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c20-if-you-can-avoid-defining-default-operations-do Added compile-time checks of the type traits of the special member functions of `TimeStamp`.
1 parent 7fdb6d6 commit 83f6cab

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

Modules/Core/Common/include/itkTimeStamp.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ class ITKCommon_EXPORT TimeStamp
7070
static Self *
7171
New();
7272

73-
/** Constructor must remain public because classes instantiate
74-
* TimeStamps implicitly in their construction. */
75-
TimeStamp() { m_ModifiedTime = 0; }
76-
7773
/** Destoy this instance. */
7874
void
7975
Delete()
@@ -120,17 +116,12 @@ class ITKCommon_EXPORT TimeStamp
120116
/** Allow for typecasting to unsigned long. */
121117
operator ModifiedTimeType() const { return m_ModifiedTime; }
122118

123-
/** Assignment operator, allows to initialize one time stamp by copying from
124-
* another. */
125-
Self &
126-
operator=(const Self & other) = default;
127-
128119
private:
129120
/** Set/Get the pointer to GlobalTimeStamp.
130121
* Note that SetGlobalTimeStamp is not concurrent thread safe. */
131122
itkGetGlobalDeclarationMacro(GlobalTimeStampType, GlobalTimeStamp);
132123

133-
ModifiedTimeType m_ModifiedTime;
124+
ModifiedTimeType m_ModifiedTime{ 0 };
134125

135126
/** The static GlobalTimeStamp. This is initialized to NULL as the first
136127
* stage of static initialization. It is then populated on the first call to

Modules/Core/Common/test/itkTimeStampTest.cxx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@
1616
*
1717
*=========================================================================*/
1818

19-
#include <iostream>
2019
#include "itkTimeStamp.h"
2120
#include "itkMultiThreaderBase.h"
2221

22+
#include <iostream>
23+
#include <type_traits>
24+
25+
static_assert(std::is_nothrow_default_constructible<itk::TimeStamp>::value, "Check TimeStamp default-constructibility");
26+
static_assert(std::is_trivially_copy_constructible<itk::TimeStamp>::value, "Check TimeStamp copy-constructibility");
27+
static_assert(std::is_trivially_copy_assignable<itk::TimeStamp>::value, "Check TimeStamp copy-assignability");
28+
static_assert(std::is_trivially_destructible<itk::TimeStamp>::value, "Check TimeStamp destructibility");
2329

2430
// A helper struct for the test, the idea is to have one timestamp per thread.
2531
// To ease the writing of the test, we use MultiThreaderBase::SingleMethodExecute

0 commit comments

Comments
 (0)