Struct difference_t

Synopsis

#include <include/type_safe/index.hpp>

struct difference_t : strong_typedef<difference_t, ptrdiff_t>,
                      strong_typedef_op::equality_comparison<difference_t>,
                      strong_typedef_op::relational_comparison<difference_t>,
                      strong_typedef_op::unary_plus<difference_t>,
                      strong_typedef_op::unary_minus<difference_t>,
                      strong_typedef_op::addition<difference_t>,
                      strong_typedef_op::subtraction<difference_t>

Description

A type modelling the difference between two [ts::index_t]() objects.

It is a [ts::strong_typedef]() for [ts::ptrdiff_t](). It is comparable and you can add and subtract two differences. \module types

Mentioned in

Inheritance

Ancestors: strong_typedef, unary_plus, strong_typedef_op::subtraction< difference_t >, strong_typedef_op::addition< difference_t >, unary_minus, relational_comparison, equality_comparison

Methods

difference_t overload\effects Initializes it to 0.
difference_t overload\effects Initializes it from a valid signed integer type
difference_t overload\group int_ctor

Source

Lines 21-51 in include/type_safe/index.hpp.

struct difference_t : strong_typedef<difference_t, ptrdiff_t>,
                      strong_typedef_op::equality_comparison<difference_t>,
                      strong_typedef_op::relational_comparison<difference_t>,
                      strong_typedef_op::unary_plus<difference_t>,
                      strong_typedef_op::unary_minus<difference_t>,
                      strong_typedef_op::addition<difference_t>,
                      strong_typedef_op::subtraction<difference_t>
{
    /// \effects Initializes it to `0`.
    constexpr difference_t() noexcept : strong_typedef(0) {}

    /// \effects Initializes it from a valid `signed` integer type.
    /// \notes This constructor does not participate in overload resolution,
    /// if `T` is not safely convertible to [ts::ptrdiff_t]().
    /// \group int_ctor
    /// \param 1
    /// \exclude
    template <typename T, typename = typename std::enable_if<
                              detail::is_safe_integer_conversion<T, std::ptrdiff_t>::value>::type>
    constexpr difference_t(T i) noexcept : strong_typedef(i)
    {}

    /// \group int_ctor
    /// \param 1
    /// \exclude
    template <typename T, class Policy,
              typename = typename std::enable_if<
                  detail::is_safe_integer_conversion<T, std::ptrdiff_t>::value>::type>
    constexpr difference_t(integer<T, Policy> i) noexcept : strong_typedef(static_cast<T>(i))
    {}
};





Add Discussion as Guest

Log in