|
| operator T () const noexcept |
|
T const & | Get () const noexcept |
| Constant accessor to the underlying value held by the strong type.
|
|
T & | Get () noexcept |
| Non constant accessor to the underlying value held by the strong type.
|
|
|
constexpr | StrongType (T const &value) |
| Constructor.
|
|
template<class T_ = T> |
constexpr | StrongType (T &&value, std::enable_if_t<!std::is_reference< T_ >{}, std::nullptr_t >=nullptr) |
| Move constructor.
|
|
template<class T_ = T> |
constexpr | StrongType (std::enable_if_t< typename almost_self< T_ >::enable_default_constructor{}, std::nullptr_t >=nullptr) |
| Default constructor, which is defined only when enable_default_constructor is defined.
|
|
| ~StrongType ()=default |
| Destructor.
|
|
| StrongType (const StrongType &rhs)=default |
| The copy constructor.
|
|
| StrongType (StrongType &&rhs)=default |
| The move constructor.
|
|
StrongType & | operator= (const StrongType &rhs)=default |
| The (copy) operator=.
|
|
StrongType & | operator= (StrongType &&rhs)=default |
| The (move) operator=.
|
|
template<class T, class
Parameter, template< typename > class... Skills>
class MoReFEM::StrongType< T, Parameter, Skills >
Abstract class used to define a StrongType, which allows more expressive code and ensures that the order of arguments of the same underlying type is respected at call sites.
Adapted from https://github.com/joboccara/NamedType/
- Template Parameters
-
As an example we could create a class Rectangle with strong types to differentiate its width from its length as:
class StrongRectangle
{
public:
StrongRectangle (Width width, Height height) : width_(width.Get()), height_(height.Get()) {}
double getWidth() const {return width_;}
double getHeight() const {return height_;}
private:
double width_;
double height_;
};
Abstract class used to define a StrongType, which allows more expressive code and ensures that the or...
Definition StrongType.hpp:101
At the calling site we would have:
StrongRectangle rectangle((Width(5.0)), (Height((2.0))));
Note that the extra parenthesis are only required for constructors due to the most vexing parse.
As for Skills: a StrongType does not allow direct operations upon its instances. For instance the following code is invalid:
Width w1(5.);
Width w2(10.);
Width sum = w1 + w2;
The new arguments enable to add support for it; to do so we provide a new Crtp (called Addable here) which grants support for operator+:
Width w1(5.);
Width w2(10.);
Width sum = w1 + w2;
The list of possible options is in the 'Skills' subdirectory; you may define your own if needed (it is basically a Crtp). Several may be added in the declaration: