xrpld
Loading...
Searching...
No Matches
xrpl::TaggedInteger< Int, Tag > Class Template Reference

A type-safe wrap around standard integral types. More...

#include <tagged_integer.h>

Inheritance diagram for xrpl::TaggedInteger< Int, Tag >:
Collaboration diagram for xrpl::TaggedInteger< Int, Tag >:

Public Types

using value_type = Int
using tag_type = Tag

Public Member Functions

 TaggedInteger ()=default
template<class OtherInt>
constexpr TaggedInteger (OtherInt value) noexcept
bool operator< (TaggedInteger const &rhs) const noexcept
bool operator== (TaggedInteger const &rhs) const noexcept
TaggedIntegeroperator+= (TaggedInteger const &rhs) noexcept
TaggedIntegeroperator-= (TaggedInteger const &rhs) noexcept
TaggedIntegeroperator*= (TaggedInteger const &rhs) noexcept
TaggedIntegeroperator/= (TaggedInteger const &rhs) noexcept
TaggedIntegeroperator%= (TaggedInteger const &rhs) noexcept
TaggedIntegeroperator|= (TaggedInteger const &rhs) noexcept
TaggedIntegeroperator&= (TaggedInteger const &rhs) noexcept
TaggedIntegeroperator^= (TaggedInteger const &rhs) noexcept
TaggedIntegeroperator<<= (TaggedInteger const &rhs) noexcept
TaggedIntegeroperator>>= (TaggedInteger const &rhs) noexcept
TaggedInteger operator~ () const noexcept
TaggedInteger operator+ () const noexcept
TaggedInteger operator- () const noexcept
TaggedIntegeroperator++ () noexcept
TaggedIntegeroperator-- () noexcept
 operator Int () const noexcept

Private Attributes

Int value_

Friends

std::ostreamoperator<< (std::ostream &s, TaggedInteger const &t)
std::istreamoperator>> (std::istream &s, TaggedInteger &t)
std::string to_string (TaggedInteger const &t)

Detailed Description

template<class Int, class Tag>
class xrpl::TaggedInteger< Int, Tag >

A type-safe wrap around standard integral types.

The tag is used to implement type safety, catching mismatched types at compile time. Multiple instantiations wrapping the same underlying integral type are distinct types (distinguished by tag) and will not interoperate. A tagged_integer supports all the usual assignment, arithmetic, comparison and shifting operations defined for the underlying type

The tag is not meant as a unit, which would require restricting the set of allowed arithmetic operations.

Definition at line 26 of file tagged_integer.h.

Member Typedef Documentation

◆ value_type

template<class Int, class Tag>
using xrpl::TaggedInteger< Int, Tag >::value_type = Int

Definition at line 40 of file tagged_integer.h.

◆ tag_type

template<class Int, class Tag>
using xrpl::TaggedInteger< Int, Tag >::tag_type = Tag

Definition at line 41 of file tagged_integer.h.

Constructor & Destructor Documentation

◆ TaggedInteger() [1/2]

template<class Int, class Tag>
xrpl::TaggedInteger< Int, Tag >::TaggedInteger ( )
default

◆ TaggedInteger() [2/2]

template<class Int, class Tag>
template<class OtherInt>
xrpl::TaggedInteger< Int, Tag >::TaggedInteger ( OtherInt value)
explicitconstexprnoexcept

Definition at line 48 of file tagged_integer.h.

Member Function Documentation

◆ operator<()

template<class Int, class Tag>
bool xrpl::TaggedInteger< Int, Tag >::operator< ( TaggedInteger< Int, Tag > const & rhs) const
noexcept

Definition at line 53 of file tagged_integer.h.

◆ operator==()

template<class Int, class Tag>
bool xrpl::TaggedInteger< Int, Tag >::operator== ( TaggedInteger< Int, Tag > const & rhs) const
noexcept

Definition at line 60 of file tagged_integer.h.

◆ operator+=()

template<class Int, class Tag>
TaggedInteger & xrpl::TaggedInteger< Int, Tag >::operator+= ( TaggedInteger< Int, Tag > const & rhs)
noexcept

Definition at line 66 of file tagged_integer.h.

◆ operator-=()

template<class Int, class Tag>
TaggedInteger & xrpl::TaggedInteger< Int, Tag >::operator-= ( TaggedInteger< Int, Tag > const & rhs)
noexcept

Definition at line 73 of file tagged_integer.h.

◆ operator*=()

template<class Int, class Tag>
TaggedInteger & xrpl::TaggedInteger< Int, Tag >::operator*= ( TaggedInteger< Int, Tag > const & rhs)
noexcept

Definition at line 80 of file tagged_integer.h.

◆ operator/=()

template<class Int, class Tag>
TaggedInteger & xrpl::TaggedInteger< Int, Tag >::operator/= ( TaggedInteger< Int, Tag > const & rhs)
noexcept

Definition at line 87 of file tagged_integer.h.

◆ operator%=()

template<class Int, class Tag>
TaggedInteger & xrpl::TaggedInteger< Int, Tag >::operator%= ( TaggedInteger< Int, Tag > const & rhs)
noexcept

Definition at line 94 of file tagged_integer.h.

◆ operator|=()

template<class Int, class Tag>
TaggedInteger & xrpl::TaggedInteger< Int, Tag >::operator|= ( TaggedInteger< Int, Tag > const & rhs)
noexcept

Definition at line 101 of file tagged_integer.h.

◆ operator&=()

template<class Int, class Tag>
TaggedInteger & xrpl::TaggedInteger< Int, Tag >::operator&= ( TaggedInteger< Int, Tag > const & rhs)
noexcept

Definition at line 108 of file tagged_integer.h.

◆ operator^=()

template<class Int, class Tag>
TaggedInteger & xrpl::TaggedInteger< Int, Tag >::operator^= ( TaggedInteger< Int, Tag > const & rhs)
noexcept

Definition at line 115 of file tagged_integer.h.

◆ operator<<=()

template<class Int, class Tag>
TaggedInteger & xrpl::TaggedInteger< Int, Tag >::operator<<= ( TaggedInteger< Int, Tag > const & rhs)
noexcept

Definition at line 121 of file tagged_integer.h.

◆ operator>>=()

template<class Int, class Tag>
TaggedInteger & xrpl::TaggedInteger< Int, Tag >::operator>>= ( TaggedInteger< Int, Tag > const & rhs)
noexcept

Definition at line 129 of file tagged_integer.h.

◆ operator~()

template<class Int, class Tag>
TaggedInteger xrpl::TaggedInteger< Int, Tag >::operator~ ( ) const
noexcept

Definition at line 136 of file tagged_integer.h.

◆ operator+()

template<class Int, class Tag>
TaggedInteger xrpl::TaggedInteger< Int, Tag >::operator+ ( ) const
noexcept

Definition at line 142 of file tagged_integer.h.

◆ operator-()

template<class Int, class Tag>
TaggedInteger xrpl::TaggedInteger< Int, Tag >::operator- ( ) const
noexcept

Definition at line 148 of file tagged_integer.h.

◆ operator++()

template<class Int, class Tag>
TaggedInteger & xrpl::TaggedInteger< Int, Tag >::operator++ ( )
noexcept

Definition at line 154 of file tagged_integer.h.

◆ operator--()

template<class Int, class Tag>
TaggedInteger & xrpl::TaggedInteger< Int, Tag >::operator-- ( )
noexcept

Definition at line 161 of file tagged_integer.h.

◆ operator Int()

template<class Int, class Tag>
xrpl::TaggedInteger< Int, Tag >::operator Int ( ) const
explicitnoexcept

Definition at line 168 of file tagged_integer.h.

◆ operator<<

template<class Int, class Tag>
std::ostream & operator<< ( std::ostream & s,
TaggedInteger< Int, Tag > const & t )
friend

Definition at line 173 of file tagged_integer.h.

◆ operator>>

template<class Int, class Tag>
std::istream & operator>> ( std::istream & s,
TaggedInteger< Int, Tag > & t )
friend

Definition at line 181 of file tagged_integer.h.

◆ to_string

template<class Int, class Tag>
std::string to_string ( TaggedInteger< Int, Tag > const & t)
friend

Definition at line 188 of file tagged_integer.h.

Member Data Documentation

◆ value_

template<class Int, class Tag>
Int xrpl::TaggedInteger< Int, Tag >::value_
private

Definition at line 37 of file tagged_integer.h.