Skip to main content

predicate_op Struct Template

Unary predicate struct template. More...

Declaration​

template <class T, class Predicate_T>
struct micro_os_plus::micro_test_plus::detail::predicate_op<T, Predicate_T> { ... }

Included Headers​

Base struct​

structunary_op<T>

Common base struct template for unary comparators. More...

Public Member Typedefs Index​

template <class T, class Predicate_T>
usingop_type = op

Marker identifying the framework expression types. More...

Public Constructors Index​

template <class U>
constexprpredicate_op (U &&t, Predicate_T)

Constructs a predicate for the given operand. More...

Public Operators Index​

template <class T, class Predicate_T>
constexproperator bool () const

Conversion operator to boolean. More...

Public Member Functions Index​

template <class T, class Predicate_T>
constexpr auto operand (void) const -> decltype(auto)

Retrieves the wrapped operand expression. More...

Private Member Attributes Index​

template <class T, class Predicate_T>
Tt_

Stores the operand. More...

template <class T, class Predicate_T>
const boolvalue_ {}

Stores the result of the operation. More...

Description​

Unary predicate struct template.

Derived from unary_op, this struct checks a property of a single operand, using the predicate defined by the tag Predicate_T, and reports the symbol of the tag followed by the operand upon failure, as not_op reports not.

It is public, as extension::predicate_op, so that the applications can define their own predicates with their own tags. A tag is an empty struct with:

  • a static constexpr const char* symbol, written before the operand in the failure reports, with the trailing space (for example "even ");
  • a static apply (operand) member function template, which receives the unwrapped operand (the value of a to_* wrapper or of a literal) and returns the result as bool.

The tag is passed as an empty constructor argument, so that both template arguments are deduced, for example predicate_op{ value, even{} }.

A temporary is moved into the predicate, and a named operand is copied (see stored_operand_t), so a predicate built in a function from its const& parameter can be returned from it.

Template Parameters
T

The type of the stored operand, either the operand type, or a const reference to it.

Predicate_T

The tag that defines the predicate. It is stateless, with a static symbol and a static apply(); a predicate that needs a parameter is a comparison of two operands (see compare_op).

Definition at line 1252 of file detail.h.

Public Member Typedefs​

op_type​

template <class T, class Predicate_T>
using micro_os_plus::micro_test_plus::detail::op::op_type = op

Marker identifying the framework expression types.

Detected by the extension::is_op concept, and inherited by all types derived from op.

Definition at line 128 of file extension.h.

128 using op_type = op;

Public Constructors​

predicate_op()​

template <class U>
micro_os_plus::micro_test_plus::detail::predicate_op< T, Predicate_T >::predicate_op (U && t, Predicate_T)
constexpr

Constructs a predicate for the given operand.

The result is computed from the argument, before it is forwarded to the base. The tag argument is used only to deduce Predicate_T.

Template Parameters
U

The type of the operand argument.

Parameters
t

The operand.

Applies the predicate of the tag to the unwrapped operand, and passes the boolean result, with the operand prepared by as_operand(), to the unary_op base class constructor.

Declaration at line 1268 of file detail.h, definition at line 1093 of file detail-inlines.h.

1094 constexpr predicate_op<T, Predicate_T>::predicate_op (U&& t, Predicate_T)
1095 : unary_op<T>{ detail::as_operand (std::forward<U> (t)),
1096 static_cast<bool> (
1097 Predicate_T::apply (detail::unwrap (t))) }
1098 {

References micro_os_plus::micro_test_plus::detail::unary_op< T >::unary_op, micro_os_plus::micro_test_plus::detail::as_operand and micro_os_plus::micro_test_plus::detail::unwrap.

Public Operators​

operator bool()​

template <class T, class Predicate_T>
micro_os_plus::micro_test_plus::detail::unary_op< T >::operator bool ()
nodiscard constexpr

Conversion operator to boolean.

Parameters

None.

Returns

The result of the operation.

Returns the pre-computed boolean result stored by the derived comparator's constructor.

Declaration at line 283 of file detail.h, definition at line 129 of file detail-inlines.h.

129 operator bool () const
130 {
131 return value_;
132 }

References micro_os_plus::micro_test_plus::detail::unary_op< T >::unary_op and micro_os_plus::micro_test_plus::detail::unary_op< T >::value_.

Public Member Functions​

operand()​

template <class T, class Predicate_T>
decltype(auto) constexpr micro_os_plus::micro_test_plus::detail::unary_op< T >::operand (void)
nodiscard constexpr

Retrieves the wrapped operand expression.

The operand is unwrapped with detail::unwrap() and returned by reference, so that formatting it does not copy it.

Parameters

None.

Returns

The extracted operand value.

Returns the operand, unwrapped by detail::unwrap() if it is a framework wrapper type; the stored operand is not copied.

Declaration at line 297 of file detail.h, definition at line 141 of file detail-inlines.h.

142 {
143 return detail::unwrap (t_);
144 }

References micro_os_plus::micro_test_plus::detail::unary_op< T >::operand, micro_os_plus::micro_test_plus::detail::unary_op< T >::t_ and micro_os_plus::micro_test_plus::detail::unwrap.

Referenced by micro_os_plus::micro_test_plus::detail::unary_op< T >::operand.

Private Member Attributes​

t_​

template <class T, class Predicate_T>
T micro_os_plus::micro_test_plus::detail::unary_op< T >::t_

Stores the operand.

A value, moved from a temporary or copied from a named operand, or, for a named operand that cannot be copied, a const reference to it (see stored_operand_t). It is not const, so that a temporary expression can be moved into an enclosing one.

Definition at line 309 of file detail.h.

309 T t_;

Referenced by micro_os_plus::micro_test_plus::detail::unary_op< T >::unary_op and micro_os_plus::micro_test_plus::detail::unary_op< T >::operand.

value_​

template <class T, class Predicate_T>
const bool micro_os_plus::micro_test_plus::detail::unary_op< T >::value_ {}

Stores the result of the operation.

Computed once, by the derived comparator constructor.

Definition at line 317 of file detail.h.

317 const bool value_{};

Referenced by micro_os_plus::micro_test_plus::detail::unary_op< T >::unary_op and micro_os_plus::micro_test_plus::detail::unary_op< T >::operator bool.


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


Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.