Table of Contents
Documentation¶
The newtype library provides types and functions to facilitate the creation of strong type aliases.
Example Usage¶
Note
All examples shown in this section can be found in the directory examples/src within the source root.
new-type-usage-basic below demonstrates the basic usage of new_type.
In it, new_type is used to create thre new strong aliases Width, Height, and Area that all alias unsigned int.
However, using new_type in this fashion seem quite cumbersome.
Starting from the bottom, unsigned int can normally be shifted on to any std::basic_ostream, like std::cout in this example.
Since printing values, among other things, is a common scenario, newtype provides facilities to support automatic derivation of supporting functions.
new-type-usage-basic-show demonstrates how the function template deriving() can be used to enable automatic derivation of the stream output operator for Area.
Similarly, it is possible to derive the stream input operators of Width and Height, as shown in new-type-usage-basic-read below.
API¶
This section of the documentation describes the public API of the new_type.
It provides detailed descriptions of the types and functions designed to be used by applications.
All declarations described in this section are found in the namespace nt, unless noted otherwise.
Header <newtype/new_type.hpp>¶
This header contains the definitions of the class template new_type as well as a set of associated namespace-level functions.
Class template new_type¶
-
template<typename
BaseType, typenameTagType, autoDerivationClause= deriving()>
classnew_type¶ The class template
new_typeis designed to allow the creation of new types based on existing types. Similarly to the Haskell newtype, this class template creates a new type that is layout equivalent to the underlying type.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
New in version 1.0.0.
Member Type Aliases
-
using
derivation_clause_type= decltype(DerivationClause)¶
-
using
iterator= typename BaseType::iterator¶ - Enablement
This type alias shall be defined iff. this
new_type’sbase_typehas a member typeiteratorand thederivation clausecontainsIterable.
New in version 1.1.0.
-
using
const_iterator= typename BaseType::const_iterator¶ - Enablement
This type alias shall be defined iff. this
new_type’sbase_typehas a member typeconst_iteratorand thederivation clausecontainsIterable.
New in version 1.1.0.
-
using
reverse_iterator= typename BaseType::reverse_iterator¶ - Enablement
This type alias shall be defined iff. this
new_type’sbase_typehas a member typereverse_iteratorand thederivation clausecontainsIterable.
New in version 1.1.0.
-
using
const_reverse_iterator= typename BaseType::const_reverse_iterator¶ - Enablement
This type alias shall be defined iff. this
new_type’sbase_typehas a member typeconst_reverse_iteratorand thederivation clausecontainsIterable.
New in version 1.1.0.
Static Data Members
-
static derivation_clause_type constexpr
derivation_clause= DerivationClause¶
Constructors
-
constexpr
new_type()¶ Construct a new instance of this
new_typeby default constructing the contained object.- Throws
Any exception thrown by the default constructor of this
new_type’sbase_type. This constructor shall be noexcept iff. thisnew_type’sbase_typeis nothrow default-construtible.- Enablement
This constructor shall be defined as
= defaultiff. thisnew_type’sbase_typeis default-construtible. Otherwise, this constructor shall be explicitely deleted.
-
constexpr
new_type(new_type const &other)¶ Construct a new instance of this
new_typeby copy-constructing the contained object using the value contained byother.- Parameters
other – An existing instance of this
new_type- Throws
Any exception thrown by the copy-constructor of this
new_type’sbase_type. This constructor shall be noexcept iff. thisnew_type’sbase_typeis nothrow copy-construtible.- Enablement
This constructor shall be defined as
= defaultiff. thisnew_type’sbase_typeis copy-construtible. Otherwise, this constructor shall be explicitely deleted.
-
constexpr
new_type(new_type &&other)¶ Construct a new instance of this
new_typeby move-constructing the contained object using the value contained byother.- Parameters
other – An existing instance of this
new_type- Throws
Any exception thrown by the move-constructor of this
new_type’sbase_type. This constructor shall be noexcept iff. thisnew_type’sbase_typeis nothrow move-construtible.- Enablement
This constructor shall be defined as
= defaultiff. thisnew_type’sbase_typeis move-construtible. Otherwise, this constructor shall be explicitely deleted.
-
constexpr
new_type(BaseType const &value)¶ Construct a new instance of this
new_typeby copy-constructing the contained object usingvalue.- Parameters
value – An existing instance of this
new_type- Throws
Any exception thrown by the copy-constructor of this
new_type’sbase_type. This constructor shall be noexcept iff. thisnew_type’sbase_typeis nothrow copy-construtible.- Enablement
This constructor shall be defined as
= defaultiff. thisnew_type’sbase_typeis copy-construtible. Otherwise, this constructor shall be explicitely deleted.
-
constexpr
new_type(BaseType &&value)¶ Construct a new instance of this
new_typeby move-constructing the contained object usingvalue.- Parameters
value – An existing instance of this
new_type- Throws
Any exception thrown by the move-constructor of this
new_type’sbase_type. This constructor shall be noexcept iff. thisnew_type’sbase_typeis nothrow move-construtible.- Enablement
This constructor shall be defined as
= defaultiff. thisnew_type’sbase_typeis move-construtible. Otherwise, this constructor shall be explicitely deleted.
Assignment Operators
-
constexpr new_type &
operator=(new_type const &other)¶ Copy the value of an existing instance of this
new_typeand replace this instance’s value- Parameters
other – An existing instance of this
new_type- Throws
Any exception thrown by the copy-assignment operator of this
new_type’sbase_type. This operator shall be noexcept iff. thisnew_type’sbase_typeis nothrow copy-assignable.- Enablement
This operator shall be defined as
= defaultiff. thisnew_type’sbase_typeis copy-assignable. Otherwise, this operator shall be explicitely deleted.
-
constexpr new_type &
operator=(new_type &&other)¶ Move the value of an existing instance of this
new_typeand replace this instance’s value- Parameters
other – An existing instance of this
new_type- Throws
Any exception thrown by the move-assignment operator of this
new_type’sbase_type. This operator shall be noexcept iff. thisnew_type’sbase_typeis nothrow move-assignable.- Enablement
This operator shall be defined as
= defaultiff. thisnew_type’sbase_typeis move-assignable. Otherwise, this operator shall be explicitely deleted.
Accessors
-
constexpr
operator BaseType() const¶ Retrieve a copy of the object contained by this
new_typeobject- Throws
Any exception thrown by the copy-constructor of this
new_type’sbase_type. This operator shall be noexcept iff. thisnew_type’sbase_typeis nothrow copy-constructible.- Explicit
This conversion operator shall be explicit unless this
new_type’sderivation clausecontainsImplicitConversion.
Member Access Through Pointer
-
constexpr BaseType
operator->() noexcept¶ Perform “member access through pointer” via a pointer to object contained by this
new_type- Enablement
This operator shall be available iff. this
new_type’sderivation clausecontainsIndirection
-
constexpr BaseType const *
operator->() const noexcept¶ Perform “member access through pointer” via a pointer to object contained by this
new_type- Enablement
This operator shall be available iff. this
new_type’sderivation clausecontainsIndirection
Iterators
-
constexpr iterator
begin()¶ Get an iterator to the beginning of the object contained by this
new_type- Enablement
This function shall be available iff.
New in version 1.1.0.
-
constexpr iterator
begin() const¶ Get a constant iterator to the beginning of the object contained by this
new_type- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandthis
new_type’sbase typehas a non-static member functionbegin() constthat returns an instance of typeconst_iterator
New in version 1.1.0.
-
constexpr iterator
cbegin() const¶ Get a constant iterator to the beginning of the object contained by this
new_type- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandthis
new_type’sbase typehas a non-static member functioncbegin() constthat returns an instance of typeconst_iterator
New in version 1.1.0.
-
constexpr iterator
rbegin()¶ Get a reverse iterator to the beginning of the object contained by this
new_type- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandthis
new_type’sbase typehas a non-static member functionrbegin()that returns an instance of typereverse_iterator
New in version 1.1.0.
-
constexpr iterator
rbegin() const¶ Get a constant reverse iterator to the beginning of the object contained by this
new_type- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandthis
new_type’sbase typehas a non-static member functionrbegin() constthat returns an instance of typeconst_reverse_iterator
New in version 1.1.0.
-
constexpr iterator
crbegin() const¶ Get a constant reverse iterator to the beginning of the object contained by this
new_type- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandthis
new_type’sbase typehas a non-static member functioncrbegin() constthat returns an instance of typeconst_reverse_iterator
New in version 1.1.0.
-
constexpr iterator
end()¶ Get an iterator beyond the end of the object contained by this
new_type- Enablement
This function shall be available iff.
New in version 1.1.0.
-
constexpr iterator
end() const¶ Get a constant iterator beyond the end of the object contained by this
new_type- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandthis
new_type’sbase typehas a non-static member functionend() constthat returns an instance of typeconst_iterator
New in version 1.1.0.
-
constexpr iterator
cend() const¶ Get a constant iterator beyond the end of the object contained by this
new_type- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandthis
new_type’sbase typehas a non-static member functioncend() constthat returns an instance of typeconst_iterator
New in version 1.1.0.
-
constexpr iterator
rend()¶ Get a reverse iterator beyond the end of the object contained by this
new_type- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandthis
new_type’sbase typehas a non-static member functionrend()that returns an instance of typereverse_iterator
New in version 1.1.0.
-
constexpr iterator
rend() const¶ Get a constant reverse iterator beyond the end of the object contained by this
new_type- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandthis
new_type’sbase typehas a non-static member functionrend() constthat returns an instance of typeconst_reverse_iterator
New in version 1.1.0.
-
constexpr iterator
crend() const¶ Get a constant reverse iterator beyond the end of the object contained by this
new_type- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandthis
new_type’sbase typehas a non-static member functioncrend() constthat returns an instance of typeconst_reverse_iterator
New in version 1.1.0.
namespace-level functions and function templates¶
The functions and functions templates described in this section provide additional functionality for the class template new_type that is not part of the class itself.
Equality Comparison Operators¶
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr booloperator==(new_type<BaseType, TagType, DerivationClause> const &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Check two instances of
new_type<BaseType, TagType, DerivationClause>for equality.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the comparison
rhs – The right-hand side of the comparison
- Returns
The value returned by the comparison of the contained objects.
- Throws
Any exception thrown by the comparison operator of objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow equals-comparable.- Enablement
This operator shall be available iff.
new_type::base_typesupports comparison using==
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr booloperator==(new_type<BaseType, TagType, DerivationClause> const &lhs, BaseType const &rhs)¶ Check an instance of
new_type<BaseType, TagType, DerivationClause>for equality with an instance ofBaseType.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the comparison
rhs – The right-hand side of the comparison
- Returns
The value returned by the comparison of object contained by
lhswith an object of thebase type.- Throws
Any exception thrown by the comparison of object contained by
lhswith an object of thebase type. This operator shall be noexcept iff.new_type::base_typeis nothrow equals-comparable.- Enablement
This operator shall be available iff.
new_type::base_typesupports comparison using==andthe
derivation clausecontainsEqBase
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr booloperator==(BaseType const &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Check an instance of
BaseTypefor equality with an instance ofnew_type<BaseType, TagType, DerivationClause>.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the comparison
rhs – The right-hand side of the comparison
- Returns
The value returned by the comparison of an object of
base typewith the object contained byrhs.- Throws
Any exception thrown by the comparison of an object of
base typewith the object contained byrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow equals-comparable.- Enablement
This operator shall be available iff.
new_type::base_typesupports comparison using==andthe
derivation clausecontainsEqBase
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr booloperator!=(new_type<BaseType, TagType, DerivationClause> const &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Check two instances of
new_type<BaseType, TagType, DerivationClause>for in-equality.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the comparison
rhs – The right-hand side of the comparison
- Returns
The value returned by the comparison of the contained objects.
- Throws
Any exception thrown by the comparison operator of theobjects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow not-equals-comparable.- Enablement
This operator shall be available iff.
new_type::base_typesupports comparison using!=
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr booloperator!=(new_type<BaseType, TagType, DerivationClause> const &lhs, BaseType const &rhs)¶ Check an instance of
new_type<BaseType, TagType, DerivationClause>for in-equality with an instance ofBaseType.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the comparison
rhs – The right-hand side of the comparison
- Returns
The value returned by the comparison of the object contained by
lhswith an object of thebase type.- Throws
Any exception thrown by the comparison of the object contained by
lhswith an object of thebase type. This operator shall be noexcept iff.new_type::base_typeis nothrow not-equals-comparable.- Enablement
This operator shall be available iff.
new_type::base_typesupports comparison using!=andthe
derivation clausecontainsEqBase
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr booloperator!=(BaseType const &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Check an instance of
BaseTypefor in-equality with an instance ofnew_type<BaseType, TagType, DerivationClause>.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the comparison
rhs – The right-hand side of the comparison
- Returns
The value returned by the comparison of an object of
base typewith the object contained byrhs.- Throws
Any exception thrown by the comparison of an object of
base typewith the object contained byrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow not-equals-comparable.- Enablement
This operator shall be available iff.
new_type::base_typesupports comparison using!=andthe
derivation clausecontainsEqBase
New in version 1.0.0.
Relational Comparison Operators¶
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr booloperator<(new_type<BaseType, TagType, DerivationClause> const &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Compare two instances of the same
new_typeusing<(less-than).- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the comparison
rhs – The right-hand side of the comparison
- Returns
The value returned by the comparison of the contained objects.
- Throws
Any exception thrown by the comparison operator of the objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow less-than-comparable.- Enablement
This operator shall be available iff.
new_type::base_typesupports comparison using<andthe
derivation clausecontainsRelational
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr booloperator>(new_type<BaseType, TagType, DerivationClause> const &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Compare two instances of the same
new_typeusing>(greater-than).- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the comparison
rhs – The right-hand side of the comparison
- Returns
The value returned by the comparison of the contained objects.
- Throws
Any exception thrown by the comparison operator of the objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow greater-than-comparable.- Enablement
This operator shall be available iff.
new_type::base_typesupports comparison using>andthe
derivation clausecontainsRelational
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr booloperator<=(new_type<BaseType, TagType, DerivationClause> const &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Compare two instances of the same
new_typeusing<=(less-than-equal).- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the comparison
rhs – The right-hand side of the comparison
- Returns
The value returned by the comparison of the contained objects.
- Throws
Any exception thrown by the comparison operator of the objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow less-than-equal-comparable.- Enablement
This operator shall be available iff.
new_type::base_typesupports comparison using<=andthe
derivation clausecontainsRelational
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr booloperator>=(new_type<BaseType, TagType, DerivationClause> const &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Compare two instances of the same
new_typeusing>=(greater-than-equal).- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the comparison
rhs – The right-hand side of the comparison
- Returns
The value returned by the comparison of the contained objects.
- Throws
Any exception thrown by the comparison operator of the objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow greater-than-equal-comparable.- Enablement
This operator shall be available iff.
new_type::base_typesupports comparison using>=andthe
derivation clausecontainsRelational
New in version 1.0.0.
Stream I/O Operators¶
-
template<typename
BaseType, typenameTagType, autoDerivationClause, typenameCharType, typenameStreamTraits>
std::basic_ostream<CharType, StreamTraits> &operator<<(std::basic_ostream<CharType, StreamTraits> &out, new_type<BaseType, TagType, DerivationClause> const &value)¶ Write an instance of
new_type<BaseType, TagType, DerivationClause>to a standardostream.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()CharType – The stream character type
StreamTraits – The traits of the output stream
- Parameters
out – The output stream
value – A
new_typevalue to write to the output stream
- Returns
A reference to the output stream
- Throws
Any exception thrown by the stream-output operator of the object contained by
value. This operator shall be noexcept iff.new_type::base_typeis nothrow output-streamable.- Enablement
This operator shall be available iff.
new_type::base_typesupports being written to an output stream using<<andthe
derivation clausecontainsShow
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause, typenameCharType, typenameStreamTraits>
std::basic_istream<CharType, StreamTraits> &operator>>(std::basic_istream<CharType, StreamTraits> &in, new_type<BaseType, TagType, DerivationClause> &value)¶ Read an instance of
new_type<BaseType, TagType, DerivationClause>from a standardistream.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()CharType – The stream character type
StreamTraits – The traits of the input stream
- Parameters
in – The input stream
value – A
new_typevalue to be read from the output stream
- Returns
A reference to the input stream
- Throws
Any exception thrown by the stream-input operator of the object contained by
value. This operator shall be noexcept iff.new_type::base_typeis nothrow input-streamable.- Enablement
This operator shall be available iff.
new_type::base_typesupports being read from an input stream using>>andthe
derivation clausecontainsRead
New in version 1.0.0.
Arithmetic Operators¶
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>operator+(new_type<BaseType, TagType, DerivationClause> const &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Add two instances of the same
new_type.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the addition
rhs – The right-hand side of the addition
- Returns
A new instance of
new_type<BaseType, TagType, DerivationClause>containing the result of applying+to the objects contained bylhsandrhs.- Throws
Any exception thrown by the addition operator of the objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow addable andnew_type::base_typeis nothrow copy-constructible
- Enablement
This operator shall be available iff.
new_type::base_typesupports addition using+andthe
derivation clausecontainsArithmetic
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause> &operator+=(new_type<BaseType, TagType, DerivationClause> &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Add two instances of the same
new_typeby overwriting the first one.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the addition
rhs – The right-hand side of the addition
- Returns
A reference to the first argument containing the value modified by applying
+=to the objects contained bylhsandrhs.- Throws
Any exception thrown by the addition-assignment operator of the objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow add-assignable andnew_type::base_typeis nothrow copy-constructible
- Enablement
This operator shall be available iff.
new_type::base_typesupports addition using+=andthe
derivation clausecontainsArithmetic
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>operator-(new_type<BaseType, TagType, DerivationClause> const &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Subtract two instances of the same
new_type.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the subtraction
rhs – The right-hand side of the subtraction
- Returns
A new instance of
new_type<BaseType, TagType, DerivationClause>containing the result of applying-to the objects contained bylhsandrhs.- Throws
Any exception thrown by the subtraction operator of the objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow subtractable andnew_type::base_typeis nothrow copy-constructible
- Enablement
This operator shall be available iff.
new_type::base_typesupports subtraction using-andthe
derivation clausecontainsArithmetic
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause> &operator-=(new_type<BaseType, TagType, DerivationClause> &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Subtract two instances of the same
new_typeby overwriting the first one.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the subtraction
rhs – The right-hand side of the subtraction
- Returns
A reference to the first argument containing the value modified by applying
-=to the objects contained bylhsandrhs.- Throws
Any exception thrown by the subtraction-assignment operator of the objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow subtract-assignable andnew_type::base_typeis nothrow copy-constructible
- Enablement
This operator shall be available iff.
new_type::base_typesupports subtraction using-=andthe
derivation clausecontainsArithmetic
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>operator*(new_type<BaseType, TagType, DerivationClause> const &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Multiply two instances of the same
new_type.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the multiplication
rhs – The right-hand side of the multiplication
- Returns
A new instance of
new_type<BaseType, TagType, DerivationClause>containing the result of applying*to the objects contained bylhsandrhs.- Throws
Any exception thrown by the multiplication operator of the objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow multipliable andnew_type::base_typeis nothrow copy-constructible
- Enablement
This operator shall be available iff.
new_type::base_typesupports multiplication using*andthe
derivation clausecontainsArithmetic
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause> &operator*=(new_type<BaseType, TagType, DerivationClause> &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Multiply two instances of the same
new_typeby overwriting the first one.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the multiplication
rhs – The right-hand side of the multiplication
- Returns
A reference to the first argument containing the value modified by applying
*=to the objects contained bylhsandrhs.- Throws
Any exception thrown by the multiplication-assignment operator of the objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow multiply-assignable andnew_type::base_typeis nothrow copy-constructible
- Enablement
This operator shall be available iff.
new_type::base_typesupports multiplication using*=andthe
derivation clausecontainsArithmetic
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>operator/(new_type<BaseType, TagType, DerivationClause> const &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Divide two instances of the same
new_type.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the division
rhs – The right-hand side of the division
- Returns
A new instance of
new_type<BaseType, TagType, DerivationClause>containing the result of applying/to the objects contained bylhsandrhs.- Throws
Any exception thrown by the division operator of the objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow dividable andnew_type::base_typeis nothrow copy-constructible
- Enablement
This operator shall be available iff.
new_type::base_typesupports division using/andthe
derivation clausecontainsArithmetic
New in version 1.0.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause> &operator/=(new_type<BaseType, TagType, DerivationClause> &lhs, new_type<BaseType, TagType, DerivationClause> const &rhs)¶ Divide two instances of the same
new_typeby overwriting the first one.- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
lhs – The left-hand side of the division
rhs – The right-hand side of the division
- Returns
A reference to the first argument containing the value modified by applying
/=to the objects contained bylhsandrhs.- Throws
Any exception thrown by the division-assignment operator of the objects contained by
lhsandrhs. This operator shall be noexcept iff.new_type::base_typeis nothrow divide-assignable andnew_type::base_typeis nothrow copy-constructible
- Enablement
This operator shall be available iff.
new_type::base_typesupports division using/=andthe
derivation clausecontainsArithmetic
New in version 1.0.0.
Iterators¶
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>::iteratorbegin(new_type<BaseType, TagType, DerivationClause> &obj)¶ Get an iterator to the beginning of the object contained by an instance of
new_type- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
obj – The object to retrieve the iterator from
- Returns
An iterator to the begining of the object of contained by
obj.- Throws
Any exception
- Enablement
This function shall be available iff.
derivation clausecontainsIterableandfor the
new_type’sbase typeexists a namespace-level functionbegin(BaseType &)that returns an instance of typenew_type::iterator
New in version 1.1.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>::const_iteratorbegin(new_type<BaseType, TagType, DerivationClause> const &obj)¶ Get a constant iterator to the beginning of the object contained by an instance of
new_type- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
obj – The object to retrieve the iterator from
- Returns
An iterator to the begining of the object of contained by
obj.- Throws
Any exception
- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandfor the
new_type’sbase typeexists a namespace-level functionbegin(BaseType const &)that returns an instance of typenew_type::const_iterator
New in version 1.1.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>::const_iteratorcbegin(new_type<BaseType, TagType, DerivationClause> const &obj)¶ Get a constant iterator to the beginning of the object contained by an instance of
new_type- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
obj – The object to retrieve the iterator from
- Returns
An iterator to the begining of the object of contained by
obj.- Throws
Any exception
- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandfor the
new_type’sbase typeexists a namespace-level functioncbegin(BaseType const &)that returns an instance of typenew_type::const_iterator
New in version 1.1.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>::reverse_iteratorrbegin(new_type<BaseType, TagType, DerivationClause> &obj)¶ Get a reverse iterator to the beginning of the object contained by an instance of
new_type- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
obj – The object to retrieve the iterator from
- Returns
An iterator to the begining of the object of contained by
obj.- Throws
Any exception
- Enablement
This function shall be available iff.
derivation clausecontainsIterableandfor the
new_type’sbase typeexists a namespace-level functionrbegin(BaseType &)that returns an instance of typenew_type::reverse_iterator
New in version 1.1.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>::const_reverse_iteratorrbegin(new_type<BaseType, TagType, DerivationClause> const &obj)¶ Get a constant reverse iterator to the beginning of the object contained by an instance of
new_type- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
obj – The object to retrieve the iterator from
- Returns
An iterator to the begining of the object of contained by
obj.- Throws
Any exception
- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandfor the
new_type’sbase typeexists a namespace-level functionrbegin(BaseType const &)that returns an instance of typenew_type::const_reverse_iterator
New in version 1.1.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>::const_reverse_iteratorcrbegin(new_type<BaseType, TagType, DerivationClause> const &obj)¶ Get a constant reverse iterator to the beginning of the object contained by an instance of
new_type- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
obj – The object to retrieve the iterator from
- Returns
An iterator to the begining of the object of contained by
obj.- Throws
Any exception
- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandfor the
new_type’sbase typeexists a namespace-level functioncrbegin(BaseType const &)that returns an instance of typenew_type::const_reverse_iterator
New in version 1.1.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>::iteratorend(new_type<BaseType, TagType, DerivationClause> &obj)¶ Get an iterator beyond the end of the object contained by an instance of
new_type- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
obj – The object to retrieve the iterator from
- Returns
An iterator beyond the end of the object of contained by
obj.- Throws
Any exception
- Enablement
This function shall be available iff.
derivation clausecontainsIterableandfor the
new_type’sbase typeexists a namespace-level functionend(BaseType &)that returns an instance of typenew_type::iterator
New in version 1.1.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>::const_iteratorend(new_type<BaseType, TagType, DerivationClause> const &obj)¶ Get a constant iterator beyond the end of the object contained by an instance of
new_type- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
obj – The object to retrieve the iterator from
- Returns
An iterator beyond the end of the object of contained by
obj.- Throws
Any exception
- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandfor the
new_type’sbase typeexists a namespace-level functionend(BaseType const &)that returns an instance of typenew_type::const_iterator
New in version 1.1.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>::const_iteratorcend(new_type<BaseType, TagType, DerivationClause> const &obj)¶ Get a constant iterator beyond the end of the object contained by an instance of
new_type- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
obj – The object to retrieve the iterator from
- Returns
An iterator beyond the end of the object of contained by
obj.- Throws
Any exception
- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandfor the
new_type’sbase typeexists a namespace-level functioncend(BaseType const &)that returns an instance of typenew_type::const_iterator
New in version 1.1.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>::reverse_iteratorrend(new_type<BaseType, TagType, DerivationClause> &obj)¶ Get a reverse iterator beyond the end of the object contained by an instance of
new_type- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
obj – The object to retrieve the iterator from
- Returns
An iterator beyond the end of the object of contained by
obj.- Throws
Any exception
- Enablement
This function shall be available iff.
derivation clausecontainsIterableandfor the
new_type’sbase typeexists a namespace-level functionrend(BaseType &)that returns an instance of typenew_type::reverse_iterator
New in version 1.1.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>::const_reverse_iteratorrend(new_type<BaseType, TagType, DerivationClause> const &obj)¶ Get a constant reverse iterator beyond the end of the object contained by an instance of
new_type- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
obj – The object to retrieve the iterator from
- Returns
An iterator beyond the end of the object of contained by
obj.- Throws
Any exception
- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandfor the
new_type’sbase typeexists a namespace-level functionrend(BaseType const &)that returns an instance of typenew_type::const_reverse_iterator
New in version 1.1.0.
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
constexpr new_type<BaseType, TagType, DerivationClause>::const_reverse_iteratorcrend(new_type<BaseType, TagType, DerivationClause> const &obj)¶ Get a constant reverse iterator beyond the end of the object contained by an instance of
new_type- Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
- Parameters
obj – The object to retrieve the iterator from
- Returns
An iterator beyond the end of the object of contained by
obj.- Throws
Any exception
- Enablement
This function shall be available iff.
this
new_type’sderivation clausecontainsIterableandfor the
new_type’sbase typeexists a namespace-level functioncrend(BaseType const &)that returns an instance of typenew_type::const_reverse_iterator
New in version 1.1.0.
std::hash Support¶
-
template<typename
BaseType, typenameTagType, autoDerivationClause>
classstd::hash<nt::new_type<BaseType, TagType, DerivationClause>>¶ - Template Parameters
BaseType – The type of the contained object
TagType – A tag to uniquely identify an instance of
nt::new_typeDerivationClause – A (possibly empty) list of derivation tags as generated by
nt::deriving()
Hash an instance of
new_typeusing the hash implementation of thebase type.-
constexpr std::size
operator()(nt::new_type<BaseType, TagType, DerivationClause> const &value) const¶ - Parameters
value – A
nt::new_typevalue to be hashed- Returns
The result of applying
std::hashto the object contained byvalue- Throws
Any exception thrown by the call operator of the specialization of :cpp:class`std::hash` for the type of the object contained by
value.- Enablement
This operator shall be available iff.
nt::new_type::base_typeis hashable andthe
derivation clausecontainsHash.
New in version 1.0.0.
Header <newtype/derivable.hpp>¶
This header defines the alias template derivable as well as the set of standard derivation tags.
Class template derivable¶
-
template<typename
NameTag>
classderivable¶ - Template Parameters
NameTag – A tag uniquely identifing a specific derivation tag
New in version 1.0.0.
Header <newtype/deriving.hpp>¶
This header contains the definition of the function template deriving().
Function template deriving()¶
-
template<typename ...
DerivableTags>
constexpr derivation_clause<DerivableTags...>deriving(derivable<DerivableTags>... features) noexcept¶ This function can be used to create a new
derivation_clausefor use in the definitions of instances ofnew_type.New in version 1.0.0.
See also
Standard derivation tags for a list of standard derivation tags
Header <newtype/derivation_clause.hpp>¶
This header contains the definition of the class template derivation_clause
Class template derivation_clause¶
-
template<typename ...
DerivableTags>
classderivation_clause¶ Derivation clauses are used by
new_typeto allow users to specify a set of automatically derived support functions.- Template Parameters
DerivableTags – A (potentially empty) list of tag types identifying the contained derivations
New in version 1.0.0.
Constructors
-
constexpr
derivation_clause(derivable<DerivableTags>...) noexcept¶ Construct a new derivations clause containing the given derivations
Evaluation Functions
-
template<typename
DerivableTag>
constexpr booloperator()(derivable<DerivableTag>) const noexcept¶ Check if this
derivation clausecontains the given derivation- Template Parameters
DerivableTag – A tag uniquely identifying a derivation
-
template<typename
DerivableTag, typename ...RemainingDerivableTags>
constexpr booloperator()(derivable<DerivableTag>, derivable<RemainingDerivableTags>...) const noexcept¶ Check if this
derivation clausecontains all of the given derivations- Template Parameters
DerivableTag – A tag uniquely identifying a derivation
RemainingDerivableTags – A list of tags uniquely identifying a list of derivations
Equality Comparison Operators
-
template<typename ...
OtherDerivableTags>
constexpr booloperator==(derivation_clause<OtherDerivableTags...> other) const noexcept¶ Check if this
derivation clauseis identical to the one represented byother. Two derivation clauses are considered equal iff. both contain the same derivations irrespective of their order.- Template Parameters
OtherDerivableTags – A (potentialy empty) list of tags uniquely identifying a list of derivations
- Parameters
other – An existing
derivation clause
-
template<typename ...
OtherDerivableTags>
constexpr booloperator!=(derivation_clause<OtherDerivableTags...> other) const noexcept¶ Check if this
derivation clauseis different from the one represented byother. Two derivation clauses are considered different iff. one contains at least one derivation not contained by the other.- Template Parameters
OtherDerivableTags – A (potentialy empty) list of tags uniquely identifying a list of derivations
- Parameters
other – An existing
derivation clause
Relational Comparison Operators
-
template<typename ...
OtherDerivableTags>
constexpr booloperator<(derivation_clause<OtherDerivableTags...> other) const noexcept¶ Check if this
derivation clauseis a subset of the one represented byother. Onederivation clauseis considered to be a subset of another iff. the list of derivations of this instance forms a proper subset of the list of derivations of the other.- Template Parameters
OtherDerivableTags – A (potentialy empty) list of tags uniquely identifying a list of derivations
- Parameters
other – An existing
derivation clause
-
template<typename ...
OtherDerivableTags>
constexpr booloperator>(derivation_clause<OtherDerivableTags...> other) const noexcept¶ Check if this
derivation clauseis a superset of the one represented byother. Onederivation clauseis considered to be a superset of another iff. the list of derivations of this instance forms a proper superset of the list of derivations of the other.- Template Parameters
OtherDerivableTags – A (potentialy empty) list of tags uniquely identifying a list of derivations
- Parameters
other – An existing
derivation clause
-
template<typename ...
OtherDerivableTags>
constexpr booloperator<=(derivation_clause<OtherDerivableTags...> other) const noexcept¶ Check if this
derivation clauseis either identical to or a subset of the one represented byother. Onederivation clauseis considered to be identical to another iff. the list of derivations of this instance is identical to the list of derivations of the other. Onederivation clauseis considered to be a subset of another iff. the list of derivations of this instance forms a proper subset of the list of derivations of the other.- Template Parameters
OtherDerivableTags – A (potentialy empty) list of tags uniquely identifying a list of derivations
- Parameters
other – An existing
derivation clause
-
template<typename ...
OtherDerivableTags>
constexpr booloperator>=(derivation_clause<OtherDerivableTags...> other) const noexcept¶ Check if this
derivation clauseis either identical to or a superset of the one represented byother. Onederivation clauseis considered to be identical to another iff. the list of derivations of this instance is identical to the list of derivations of the other. Onederivation clauseis considered to be a superset of another iff. the list of derivations of this instance forms a proper superset of the list of derivations of the other.- Template Parameters
OtherDerivableTags – A (potentialy empty) list of tags uniquely identifying a list of derivations
- Parameters
other – An existing
derivation clause