Skip to content

Commit

Permalink
STYLE: Prefer = default to explicitly trivial implementations
Browse files Browse the repository at this point in the history
This check replaces default bodies of special member functions with
= default;. The explicitly defaulted function declarations enable more
opportunities in optimization, because the compiler might treat
explicitly defaulted functions as trivial.

Additionally, the C++11 use of = default more clearly expreses the
intent for the special member functions.
  • Loading branch information
hjmjohnson committed Feb 20, 2020
1 parent 18d43c8 commit 240751a
Show file tree
Hide file tree
Showing 173 changed files with 223 additions and 249 deletions.
2 changes: 1 addition & 1 deletion Examples/DataRepresentation/Image/ImageAdaptor3.cxx
Expand Up @@ -69,7 +69,7 @@ class VectorPixelAccessor
using InternalType = itk::CovariantVector<float, 2>;
using ExternalType = float;

VectorPixelAccessor() {}
VectorPixelAccessor() = default;

VectorPixelAccessor &
operator=(const VectorPixelAccessor & vpa) = default;
Expand Down
2 changes: 1 addition & 1 deletion Examples/DataRepresentation/Image/ImageAdaptor4.cxx
Expand Up @@ -65,7 +65,7 @@ class ThresholdingPixelAccessor
using InternalType = unsigned char;
using ExternalType = unsigned char;

ThresholdingPixelAccessor(){};
ThresholdingPixelAccessor() = default;

ExternalType
Get(const InternalType & input) const
Expand Down
2 changes: 1 addition & 1 deletion Examples/RegistrationITKv4/DeformableRegistration10.cxx
Expand Up @@ -48,7 +48,7 @@ class CommandIterationUpdate : public itk::Command
itkNewMacro(CommandIterationUpdate);

protected:
CommandIterationUpdate(){};
CommandIterationUpdate() = default;

using InternalImageType = itk::Image<float, Dimension>;
using VectorPixelType = itk::Vector<float, Dimension>;
Expand Down
2 changes: 1 addition & 1 deletion Examples/RegistrationITKv4/DeformableRegistration9.cxx
Expand Up @@ -50,7 +50,7 @@ class CommandIterationUpdate : public itk::Command
itkNewMacro(CommandIterationUpdate);

protected:
CommandIterationUpdate(){};
CommandIterationUpdate() = default;

using InternalImageType = itk::Image<float, Dimension>;
using VectorPixelType = itk::Vector<float, Dimension>;
Expand Down
2 changes: 1 addition & 1 deletion Examples/RegistrationITKv4/MultiResImageRegistration1.cxx
Expand Up @@ -279,7 +279,7 @@ class CommandIterationUpdate : public itk::Command
itkNewMacro(Self);

protected:
CommandIterationUpdate(){};
CommandIterationUpdate() = default;

public:
using OptimizerType = itk::RegularStepGradientDescentOptimizerv4<double>;
Expand Down
2 changes: 1 addition & 1 deletion Examples/RegistrationITKv4/MultiResImageRegistration2.cxx
Expand Up @@ -79,7 +79,7 @@ class CommandIterationUpdate : public itk::Command
itkNewMacro(Self);

protected:
CommandIterationUpdate(){};
CommandIterationUpdate() = default;

public:
using OptimizerType = itk::RegularStepGradientDescentOptimizer;
Expand Down
Expand Up @@ -137,7 +137,7 @@ class CommandIterationUpdate : public itk::Command
itkNewMacro(Self);

protected:
CommandIterationUpdate(){};
CommandIterationUpdate() = default;

public:
using OptimizerType = itk::GradientDescentOptimizerv4Template<double>;
Expand Down
Expand Up @@ -136,7 +136,7 @@ class CommandIterationUpdate : public itk::Command
itkNewMacro(Self);

protected:
CommandIterationUpdate(){};
CommandIterationUpdate() = default;

public:
using OptimizerType = itk::GradientDescentOptimizerv4Template<double>;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Bridge/VTK/include/itkVTKImageImport.h
Expand Up @@ -168,7 +168,7 @@ class ITK_TEMPLATE_EXPORT VTKImageImport : public ImageSource<TOutputImage>

protected:
VTKImageImport();
~VTKImageImport() override {}
~VTKImageImport() override = default;
void
PrintSelf(std::ostream & os, Indent indent) const override;

Expand Down
4 changes: 2 additions & 2 deletions Modules/Bridge/VtkGlue/include/vtkCaptureScreen.h
Expand Up @@ -34,9 +34,9 @@ class vtkCaptureScreen
: m_Renderer(iRenderer)
{}

vtkCaptureScreen() {}
vtkCaptureScreen() = default;

~vtkCaptureScreen() {}
~vtkCaptureScreen() = default;

void
operator()(const std::string & iFileName) const
Expand Down
Expand Up @@ -85,7 +85,7 @@ class TreeContainerBase : public Object
}

protected:
TreeContainerBase() {}
TreeContainerBase() = default;
~TreeContainerBase() override = default;
bool m_SubTree{ false };
};
Expand Down
Expand Up @@ -140,7 +140,7 @@ class ITK_TEMPLATE_EXPORT VectorCentralDifferenceImageFunction

protected:
VectorCentralDifferenceImageFunction();
~VectorCentralDifferenceImageFunction() override {}
~VectorCentralDifferenceImageFunction() override = default;
void
PrintSelf(std::ostream & os, Indent indent) const override;

Expand Down
2 changes: 1 addition & 1 deletion Modules/Compatibility/Deprecated/src/itkBarrier.cxx
Expand Up @@ -19,7 +19,7 @@

namespace itk
{
Barrier::Barrier() {}
Barrier::Barrier() = default;

Barrier::~Barrier() = default;

Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/include/itkImageSource.hxx
Expand Up @@ -275,10 +275,10 @@ ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
ImageSource<TOutputImage>::ThreaderCallback(void * arg)
{
using ThreadInfo = MultiThreaderBase::WorkUnitInfo;
ThreadInfo * threadInfo = static_cast<ThreadInfo *>(arg);
ThreadIdType threadId = threadInfo->WorkUnitID;
ThreadIdType threadCount = threadInfo->NumberOfWorkUnits;
ThreadStruct * str = (ThreadStruct *)(threadInfo->UserData);
auto * threadInfo = static_cast<ThreadInfo *>(arg);
ThreadIdType threadId = threadInfo->WorkUnitID;
ThreadIdType threadCount = threadInfo->NumberOfWorkUnits;
auto * str = (ThreadStruct *)(threadInfo->UserData);

// execute the actual method with appropriate output region
// first find out how many pieces extent can be split into.
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkImageToImageFilter.h
Expand Up @@ -219,7 +219,7 @@ class ITK_TEMPLATE_EXPORT ImageToImageFilter

protected:
ImageToImageFilter();
~ImageToImageFilter() override{};
~ImageToImageFilter() override = default;

void
PrintSelf(std::ostream & os, Indent indent) const override;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkLoggerOutput.h
Expand Up @@ -102,7 +102,7 @@ class ITKCommon_EXPORT LoggerOutput : public OutputWindow
}

protected:
LoggerOutput() {}
LoggerOutput() = default;
~LoggerOutput() override = default;
void
PrintSelf(std::ostream & os, Indent indent) const override;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkResourceProbe.hxx
Expand Up @@ -181,7 +181,7 @@ ValueType
ResourceProbe<ValueType, MeanType>::GetStandardDeviation()
{
using InternalComputeType = typename NumericTraits<ValueType>::RealType;
const InternalComputeType realMean = static_cast<InternalComputeType>(this->GetMean());
const auto realMean = static_cast<InternalComputeType>(this->GetMean());
std::vector<InternalComputeType> diff(this->m_ProbeValueList.size());
std::transform(this->m_ProbeValueList.begin(),
this->m_ProbeValueList.end(),
Expand Down
8 changes: 2 additions & 6 deletions Modules/Core/Common/include/itkSymmetricEigenAnalysis.h
Expand Up @@ -207,9 +207,7 @@ class ITK_TEMPLATE_EXPORT SymmetricEigenAnalysis
using EigenValueOrderType = EigenValueOrderEnum;
#endif

SymmetricEigenAnalysis()
: m_OrderEigenValues(EigenValueOrderEnum::OrderByValue)
{}
SymmetricEigenAnalysis() = default;

SymmetricEigenAnalysis(const unsigned int dimension)
: m_Dimension(dimension)
Expand Down Expand Up @@ -770,9 +768,7 @@ class ITK_TEMPLATE_EXPORT SymmetricEigenAnalysisFixedDimension
static constexpr EigenValueOrderEnum DoNotOrder = EigenValueOrderEnum::DoNotOrder;
#endif

SymmetricEigenAnalysisFixedDimension()
: m_OrderEigenValues(EigenValueOrderEnum::OrderByValue)
{}
SymmetricEigenAnalysisFixedDimension() = default;
~SymmetricEigenAnalysisFixedDimension() = default;

using MatrixType = TMatrix;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/src/itkFloatingPointExceptions.cxx
Expand Up @@ -34,7 +34,7 @@ namespace itk

struct ExceptionGlobals
{
ExceptionGlobals(){};
ExceptionGlobals() = default;
FloatingPointExceptions::ExceptionActionEnum m_ExceptionAction{ FloatingPointExceptions::ExceptionActionEnum::ABORT };
bool m_Enabled{ false };
};
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/src/itkMemoryUsageObserver.cxx
Expand Up @@ -269,7 +269,7 @@ WindowsMemoryUsageObserver::GetMemoryUsage()

/** ---- Linux Memory Usage Observer ---- */

LinuxMemoryUsageObserver::~LinuxMemoryUsageObserver() {}
LinuxMemoryUsageObserver::~LinuxMemoryUsageObserver() = default;

/** Get Memory Usage - Linux version.
* Reference for method used:
Expand Down Expand Up @@ -442,7 +442,7 @@ SysResourceMemoryUsageObserver::GetMemoryUsage()

/** ---- Mallinfo Memory Usage Observer ---- */

MallinfoMemoryUsageObserver::~MallinfoMemoryUsageObserver() {}
MallinfoMemoryUsageObserver::~MallinfoMemoryUsageObserver() = default;

MemoryUsageObserverBase::MemoryLoadType
MallinfoMemoryUsageObserver::GetMemoryUsage()
Expand Down
9 changes: 4 additions & 5 deletions Modules/Core/Common/src/itkMetaDataDictionary.cxx
Expand Up @@ -23,12 +23,11 @@ MetaDataDictionary ::MetaDataDictionary()
: m_Dictionary(std::make_shared<MetaDataDictionaryMapType>())
{}

MetaDataDictionary ::~MetaDataDictionary() {}
MetaDataDictionary ::~MetaDataDictionary() = default;

MetaDataDictionary ::MetaDataDictionary(const MetaDataDictionary & old)
// perform shallow copy, so m_Dictionary is shared
: m_Dictionary(old.m_Dictionary)
{}
// NOTE: Desired behavior is to perform shallow copy, so m_Dictionary is shared
// as is thee default behavior for copy constructors.
MetaDataDictionary ::MetaDataDictionary(const MetaDataDictionary &) = default;

MetaDataDictionary &
MetaDataDictionary ::operator=(const MetaDataDictionary & old)
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/src/itkMultiThreaderBase.cxx
Expand Up @@ -54,7 +54,7 @@ namespace itk
struct MultiThreaderBaseGlobals
{
// Initialize static members.
MultiThreaderBaseGlobals(){};
MultiThreaderBaseGlobals() = default;
// GlobalDefaultThreaderTypeIsInitialized is used only in this
// file to ensure that the ITK_GLOBAL_DEFAULT_THREADER or
// ITK_USE_THREADPOOL environmenal variables are
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/src/itkObjectFactoryBase.cxx
Expand Up @@ -117,7 +117,7 @@ struct ObjectFactoryBasePrivate
}
}

ObjectFactoryBasePrivate() {}
ObjectFactoryBasePrivate() = default;

std::list<::itk::ObjectFactoryBase *> * m_RegisteredFactories{ nullptr };
std::list<::itk::ObjectFactoryBase *> * m_InternalFactories{ nullptr };
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/src/itkSingleton.cxx
Expand Up @@ -37,7 +37,7 @@ class GlobalSingletonIndexInitializer
using Self = GlobalSingletonIndexInitializer;
using SingletonIndex = ::itk::SingletonIndex;

GlobalSingletonIndexInitializer() {}
GlobalSingletonIndexInitializer() = default;

/** Delete the time stamp if it was created. */
~GlobalSingletonIndexInitializer()
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/src/itkSmapsFileParser.cxx
Expand Up @@ -438,7 +438,7 @@ SmapsData_2_6::GetStackUsage()

/** --- VMMapData --- **/

VMMapData_10_2 ::VMMapData_10_2() {}
VMMapData_10_2 ::VMMapData_10_2() = default;

VMMapData_10_2 ::~VMMapData_10_2() = default;

Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/src/itkTBBMultiThreader.cxx
Expand Up @@ -41,7 +41,7 @@ TBBMultiThreader::TBBMultiThreader()
#endif
}

TBBMultiThreader::~TBBMultiThreader() {}
TBBMultiThreader::~TBBMultiThreader() = default;

void
TBBMultiThreader::SetSingleMethod(ThreadFunctionType f, void * data)
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/test/itkCommonTypeTraitsGTest.cxx
Expand Up @@ -98,9 +98,9 @@ TEST(CommonTypeTraits, ContinuousIndexIsPOD)
/* Dummy class without noexcept move contructors. */
struct NotNoexceptMove
{
NotNoexceptMove() {}
NotNoexceptMove() = default;
NotNoexceptMove(NotNoexceptMove &&) {}
NotNoexceptMove(const NotNoexceptMove &) {}
NotNoexceptMove(const NotNoexceptMove &) = default;
};

/* Check that move-constructing a FixedArray works as move-constructing an aggregate.
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/test/itkSmartPointerGTest.cxx
Expand Up @@ -56,7 +56,7 @@ class Derived1 : public itk::Object
}

protected:
Derived1() {}
Derived1() = default;

~Derived1() override = default;

Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/GPUCommon/include/itkGPUFunctorBase.h
Expand Up @@ -34,10 +34,10 @@ class GPUFunctorBase
{
public:
// constructor
GPUFunctorBase() {}
GPUFunctorBase() = default;

// destructor
virtual ~GPUFunctorBase() {}
virtual ~GPUFunctorBase() = default;

/** Setup GPU kernel arguments for this functor.
* \return Current argument index to set additional arguments in the GPU kernel. */
Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/GPUCommon/include/itkGPUImage.hxx
Expand Up @@ -30,8 +30,7 @@ GPUImage<TPixel, VImageDimension>::GPUImage()
}

template <typename TPixel, unsigned int VImageDimension>
GPUImage<TPixel, VImageDimension>::~GPUImage()
{}
GPUImage<TPixel, VImageDimension>::~GPUImage() = default;

template <typename TPixel, unsigned int VImageDimension>
void
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/GPUCommon/include/itkGPUImageDataManager.h
Expand Up @@ -82,8 +82,8 @@ class ITK_TEMPLATE_EXPORT GPUImageDataManager : public GPUDataManager
MakeGPUBufferUpToDate();

protected:
GPUImageDataManager() {}
~GPUImageDataManager() override {}
GPUImageDataManager() = default;
~GPUImageDataManager() override = default;

private:
WeakPointer<ImageType> m_Image; // WeakPointer has to be used here
Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/GPUCommon/include/itkGPUImageToImageFilter.hxx
Expand Up @@ -30,8 +30,7 @@ GPUImageToImageFilter<TInputImage, TOutputImage, TParentImageFilter>::GPUImageTo
}

template <typename TInputImage, typename TOutputImage, typename TParentImageFilter>
GPUImageToImageFilter<TInputImage, TOutputImage, TParentImageFilter>::~GPUImageToImageFilter()
{}
GPUImageToImageFilter<TInputImage, TOutputImage, TParentImageFilter>::~GPUImageToImageFilter() = default;

template <typename TInputImage, typename TOutputImage, typename TParentImageFilter>
void
Expand Down
6 changes: 2 additions & 4 deletions Modules/Core/GPUCommon/include/itkGPUInPlaceImageFilter.hxx
Expand Up @@ -23,12 +23,10 @@
namespace itk
{
template <typename TInputImage, typename TOutputImage, typename TParentImageFilter>
GPUInPlaceImageFilter<TInputImage, TOutputImage, TParentImageFilter>::GPUInPlaceImageFilter()
{}
GPUInPlaceImageFilter<TInputImage, TOutputImage, TParentImageFilter>::GPUInPlaceImageFilter() = default;

template <typename TInputImage, typename TOutputImage, typename TParentImageFilter>
GPUInPlaceImageFilter<TInputImage, TOutputImage, TParentImageFilter>::~GPUInPlaceImageFilter()
{}
GPUInPlaceImageFilter<TInputImage, TOutputImage, TParentImageFilter>::~GPUInPlaceImageFilter() = default;

template <typename TInputImage, typename TOutputImage, typename TParentImageFilter>
void
Expand Down
Expand Up @@ -94,8 +94,8 @@ class ITK_TEMPLATE_EXPORT GPUUnaryFunctorImageFilter
#endif // !defined( ITK_WRAPPING_PARSER )

protected:
GPUUnaryFunctorImageFilter() {}
~GPUUnaryFunctorImageFilter() override {}
GPUUnaryFunctorImageFilter() = default;
~GPUUnaryFunctorImageFilter() override = default;

void
GenerateOutputInformation() override;
Expand Down
Expand Up @@ -100,7 +100,7 @@ class ITK_TEMPLATE_EXPORT GPUDenseFiniteDifferenceImageFilter

protected:
GPUDenseFiniteDifferenceImageFilter();
~GPUDenseFiniteDifferenceImageFilter() override {}
~GPUDenseFiniteDifferenceImageFilter() override = default;
void
PrintSelf(std::ostream & os, Indent indent) const override;

Expand Down
Expand Up @@ -114,7 +114,7 @@ class GPUFiniteDifferenceFunction : public FiniteDifferenceFunction<TImageType>

protected:
GPUFiniteDifferenceFunction() { m_GPUKernelManager = GPUKernelManager::New(); }
~GPUFiniteDifferenceFunction() override {}
~GPUFiniteDifferenceFunction() override = default;

/** GPU kernel manager for GPUFiniteDifferenceFunction class */
typename GPUKernelManager::Pointer m_GPUKernelManager;
Expand Down
Expand Up @@ -40,8 +40,8 @@ GPUFiniteDifferenceImageFilter<TInputImage, TOutputImage, TParentImageFilter>::G
}

template <typename TInputImage, typename TOutputImage, typename TParentImageFilter>
GPUFiniteDifferenceImageFilter<TInputImage, TOutputImage, TParentImageFilter>::~GPUFiniteDifferenceImageFilter()
{}
GPUFiniteDifferenceImageFilter<TInputImage, TOutputImage, TParentImageFilter>::~GPUFiniteDifferenceImageFilter() =
default;

template <typename TInputImage, typename TOutputImage, typename TParentImageFilter>
void
Expand Down

0 comments on commit 240751a

Please sign in to comment.