DefaultValue.h
Classes
- Global Functions -- A templated function which sets a variable to a default value. (full description)
Interface
- inline void defaultValue(T &theValue)
Review Status
- Reviewed By:
- syang@nrao.edu
- Date Reviewed:
- 1996/03/14
- Programs:
- Tests:
Prerequisite
Etymology
The DefaultValue function name is derived from its use to fill a data type
with a default value, usually zero.
Synopsis
The DefaultValue function is passed an instance of a data type and the
variable is filled with a default value. The majority of classes may
use the templated version here. Special classes may use their own
non-templated specializations as demonstrated in
../Utilities/test/tDefaultValue.cc.
Example
Int foo = 35;
defaultValue(foo);
AlwaysAssert(foo == 0, AipsError);
Array<Float> bar;
defaultValue(bar);
AlwaysAssert(allEQ(bar, 0.0f), AipsError);
A special class may need its own implementation:
void defaultValue(MySpecialClass &val){
// make a default value be all zeros
val.operator()(IPosition(2,3,4)) = Table.keywords().defaultval();
};
Motivation
We needed a common way of setting all objects to zero or some
null/default value. Specializing a templated function seemed the only way
to reach everyone.
Template Type Argument Requirements (T)
- constructor T(Int)
- assignment operator (copy semantics)
Thrown Exceptions
To Do
Member Description
inline void defaultValue(T &theValue)