Skip to main content

integral_constant Struct Template

Struct template representing a generic integral constant. More...

Declaration​

template <auto N>
struct micro_os_plus::micro_test_plus::detail::integral_constant<N> { ... }

Included Headers​

Base struct​

structvalue_base<T>

Base struct template providing common storage and accessors for run-time value-wrapper types. More...

Public Member Typedefs Index​

template <auto N>
usingop_type = op

Marker identifying the framework expression types. More...

template <auto N>
usingvalue_type = decltype(N)

The type of the stored value. More...

Public Constructors Index​

template <auto N>
constexprintegral_constant (void) noexcept

Default constructor. More...

Public Operators Index​

template <auto N>
constexproperator decltype(N) () const noexcept

Explicit conversion operator to the underlying value type. More...

template <auto N>
constexpr autooperator- () const noexcept

Unary minus operator. More...

Public Member Functions Index​

template <auto N>
constexpr auto get (void) const noexcept -> const decltype(N) &

Getter for the stored value. More...

Private Member Attributes Index​

template <auto N>
decltype(N)value_

The stored value. More...

Public Static Attributes Index​

template <auto N>
static constexpr autovalue = N

The compile-time constant value. More...

Description​

Struct template representing a generic integral constant.

Template Parameters
N

The compile-time constant value.

The integral_constant struct template provides a compile-time constant value of an integral type, created by the integer literals. It inherits from value_base<decltype(N)>, which supplies the value_type alias, the run-time value storage, the explicit conversion operator, and the get() accessor.

This struct retains the compile-time value constant and provides a unary minus operator to obtain the negative value as a new integral_constant instance, of the same type.

Definition at line 430 of file deprecated.h.

Public Member Typedefs​

op_type​

template <auto N>
using micro_os_plus::micro_test_plus::detail::value_base< decltype(N) >::op_type =

Marker identifying the framework expression types.

Declared directly rather than inherited from op, to avoid the empty base; detected by the extension::is_op concept.

Definition at line 360 of file deprecated.h.

360 using op_type = op;

value_type​

template <auto N>
using micro_os_plus::micro_test_plus::detail::value_base< decltype(N) >::value_type =

The type of the stored value.

Exposed for use by generic code that inspects wrapper types.

Definition at line 368 of file deprecated.h.

368 using value_type = T;

Public Constructors​

integral_constant()​

template <auto N>
micro_os_plus::micro_test_plus::detail::integral_constant< N >::integral_constant (void)
constexpr noexcept

Default constructor.

Initialises the base with N.

Delegates to value_base<decltype(N)>{ N } to initialise the base.

Declaration at line 446 of file deprecated.h, definition at line 516 of file deprecated-inlines.h.

517 : value_base<decltype (N)>{ N }
518 {
519 }

Reference micro_os_plus::micro_test_plus::detail::value_base< decltype(N)>::value_base.

Referenced by micro_os_plus::micro_test_plus::detail::integral_literal and micro_os_plus::micro_test_plus::detail::integral_constant< N >::operator-.

Public Operators​

operator decltype(N)()​

template <auto N>
micro_os_plus::micro_test_plus::detail::value_base< decltype(N) >::operator decltype(N) ()
explicit nodiscard constexpr noexcept

Explicit conversion operator to the underlying value type.

Returns

The stored value as type T.

Allows explicit conversion to the encapsulated value.

Declaration at line 383 of file deprecated.h, definition at line 492 of file deprecated-inlines.h.

492 operator T () const noexcept
493 {
494 return value_;
495 }

operator-()​

template <auto N>
auto micro_os_plus::micro_test_plus::detail::integral_constant< N >::operator- ()
nodiscard constexpr noexcept

Unary minus operator.

The result has the type of N, not the type promoted by the built-in unary minus, so -1_i8 is an int8_t. The negation of an unsigned value wraps around, as for unsigned int in C++ (-1_u8 is 255). The negation of the minimum of a signed type does not fit in the type, so it is a compilation error.

Returns

An integral_constant with value -N, converted to the type of N.

The built-in unary minus promotes the types narrower than int, so its result is converted back to the type of N. For the unsigned types, the value is subtracted from zero, which, after the conversion, gives the value modulo 2^n for all widths. For the signed types, the minimum is rejected before the negation, which would otherwise overflow for int and the wider types.

Declaration at line 462 of file deprecated.h, definition at line 532 of file deprecated-inlines.h.

533 {
534 // Not named `value_type`, which would shadow the member inherited
535 // from the base (`-Wshadow`).
536 using constant_type = decltype (N);
537
538 if constexpr (!std::is_signed_v<constant_type>)
539 {
541 - N)>{};
542 }
543 else if constexpr (N == std::numeric_limits<constant_type>::min ())
544 {
545 static_assert (N != std::numeric_limits<constant_type>::min (),
546 "µTest++: the negation of the minimum value does "
547 "not fit in the type of the literal");
548 return *this;
549 }
550 else
551 {
553 }
554 }

Reference micro_os_plus::micro_test_plus::detail::integral_constant< N >::integral_constant.

Public Member Functions​

get()​

template <auto N>
const decltype(N) & micro_os_plus::micro_test_plus::detail::value_base< decltype(N) >::get (void)
nodiscard constexpr noexcept

Getter for the stored value.

Returns a reference, so that a wrapped object (for example a to_t<std::string>) is not copied each time it is compared or formatted.

Parameters

None.

Returns

A reference to the stored value.

Returns a const reference to the stored value, valid as long as the wrapper.

Declaration at line 398 of file deprecated.h, definition at line 504 of file deprecated-inlines.h.

504 value_base<T>::get (void) const noexcept
505 {
506 return value_;
507 }

Private Member Attributes​

value_​

template <auto N>
decltype(N) micro_os_plus::micro_test_plus::detail::value_base< decltype(N) >::value_

The stored value.

Set by the constructor. Derived wrappers and comparators access it via get() or the explicit conversion operator.

Definition at line 408 of file deprecated.h.

408 T value_{};

Public Static Attributes​

value​

template <auto N>
auto micro_os_plus::micro_test_plus::detail::integral_constant< N >::value = N
constexpr static

The compile-time constant value.

Equal to N; also available at run time via get().

Definition at line 438 of file deprecated.h.

438 static constexpr auto value = N;

The documentation for this struct was generated from the following files:


Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.