TrailingRequiresExample Class

A class demonstrating functions with trailing requires clauses. More...

Header: #include <TrailingRequiresExample>

Public Functions

T combine(T a, T b)
T process(T value)
double transform(T input)

Detailed Description

Trailing requires clauses appear after the function declaration, rather than after the template parameter list.

Member Function Documentation

template <typename T> requires detail::is_integral<T>::value T TrailingRequiresExample::combine(T a, T b) requires (sizeof(T) <= 4)

Combines a and b with both template-head and trailing requires.

This demonstrates a function with requires clauses in both positions, which is rare but valid C++20 syntax. Both constraints must be satisfied.

template <typename T> T TrailingRequiresExample::process(T value) requires detail::is_integral<T>::value

Processes value with a trailing requires clause.

The trailing requires clause appears after the function signature, which is an alternative syntax to placing it after the template parameter list.

template <typename T> double TrailingRequiresExample::transform(T input) requires detail::is_floating<T>::value

Transforms input using trailing constraint.

This demonstrates that trailing requires clauses work with any constraint expression.