micro-test-plus 6.0.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::detail::integral_constant< N > Struct Template Reference

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

#include "micro-os-plus/micro-test-plus.h"

Inheritance diagram for micro_os_plus::micro_test_plus::detail::integral_constant< N >:

Public Types

using op_type
 Marker identifying the framework expression types.
using value_type
 The type of the stored value.

Public Member Functions

constexpr integral_constant (void) noexcept
 Default constructor.
constexpr const decltype(N) & get (void) const noexcept
 Getter for the stored value.
constexpr operator decltype(N) () const noexcept
 Explicit conversion operator to the underlying value type.
constexpr auto operator- () const noexcept
 Unary minus operator.

Static Public Attributes

static constexpr auto value = N
 The compile-time constant value.

Private Attributes

decltype(N) value_
 The stored value.

Detailed Description

template<auto N>
struct micro_os_plus::micro_test_plus::detail::integral_constant< N >
Template Parameters
NThe 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.

Member Typedef Documentation

◆ op_type

using micro_os_plus::micro_test_plus::detail::value_base< decltype(N) >::op_type
inherited

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.

◆ value_type

using micro_os_plus::micro_test_plus::detail::value_base< decltype(N) >::value_type
inherited

Exposed for use by generic code that inspects wrapper types.

Definition at line 368 of file deprecated.h.

Constructor & Destructor Documentation

◆ integral_constant()

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

Initialises the base with N.

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

Definition at line 516 of file deprecated-inlines.h.

517 : value_base<decltype (N)>{ N }
518 {
519 }
Struct template representing a generic integral constant.
Definition deprecated.h:431

References 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 operator-().

Member Function Documentation

◆ get()

const decltype(N) & micro_os_plus::micro_test_plus::detail::value_base< decltype(N) >::get ( void ) const
nodiscardconstexprnoexceptinherited

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.

Definition at line 398 of file deprecated-inlines.h.

505 {
506 return value_;
507 }
Base struct template providing common storage and accessors for run-time value-wrapper types.
Definition deprecated.h:352

◆ operator decltype(N)()

micro_os_plus::micro_test_plus::detail::value_base< decltype(N) >::operator decltype(N) ( ) const
explicitnodiscardconstexprnoexceptinherited
Returns
The stored value as type T.

Allows explicit conversion to the encapsulated value.

Definition at line 383 of file deprecated-inlines.h.

493 {
494 return value_;
495 }

◆ operator-()

template<auto N>
auto micro_os_plus::micro_test_plus::detail::integral_constant< N >::operator- ( ) const
nodiscardconstexprnoexcept

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.

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 }
constexpr integral_constant(void) noexcept
Default constructor.

References integral_constant().

Member Data Documentation

◆ value

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

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

Definition at line 438 of file deprecated.h.

◆ value_

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

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{};

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