Macros
ClassHelpers.h File Reference
#include <type_traits>

Go to the source code of this file.

Macros

#define OFFLINE_CAST_CONST_METHOD(_Method_)
 

Macro Definition Documentation

#define OFFLINE_CAST_CONST_METHOD (   _Method_)
Value:
const_cast< \
std::remove_const_t< \
decltype(this->_Method_) \
> \
>( \
static_cast< \
std::add_const_t< \
std::remove_reference_t< \
decltype(*this) \
> \
>& \
>(*this)._Method_ \
)

To reduce unnecessary code duplication, the otherwise-identical but lengthy const and non-const methods of class can be rewritten so that only the const one has to be implemented while the other is generated by this macro. (Meyers, Effective C++) Example: original code

class Foo { Bar& GetBar(const int i); const Bar& GetBar(const int i) const; };

can be rewritten as

#include <utl/ClassHelpers.h> class Foo { Bar& GetBar(const int i) { return OFFLINE_CAST_CONST_METHOD(GetBar(i)); } const Bar& GetBar(const int i) const; };

and thus reduce the trivial boiler-plate code duplication

Author
Darko Veberic
Date
06 Jul 2022

Definition at line 51 of file ClassHelpers.h.

Referenced by revt::Station::GetChannel(), revt::Channel::GetChannelADCTimeSeries(), revt::Channel::GetFFTDataContainer(), revt::Station::GetGPSData(), sevt::PMTSimData::GetMultiTrace(), sevt::PMTSimData::GetMultiTraceD(), sevt::Station::GetPMT(), revt::Station::GetRecData(), sevt::Station::GetScintillatorPMT(), revt::Station::GetSimData(), sevt::Station::GetSmallPMT(), sevt::SEvent::GetStation(), revt::REvent::GetStation(), revt::REvent::GetStationByName(), revt::Station::GetStationHeader(), and revt::Station::GetTriggerData().


, generated on Tue Sep 26 2023.