GMP 0.3.0
Generative Metaprogramming library for C++
Loading...
Searching...
No Matches
Named Operators

Facilities for building custom infix syntax from callable objects. More...

Functions

template<typename Func >
constexpr auto gmp::make_named_operator (Func &&f)
 Create a token that lets a callable be used as a named infix operator.
 

Detailed Description

Function Documentation

◆ make_named_operator()

template<typename Func >
constexpr auto gmp::make_named_operator ( Func &&  f)
constexpr

The returned token can be placed between two matching operator symbols to call the stored callable with the left and right operands. Default generated forms include lhs ^op^ rhs, lhs <op> rhs, and matching pairs for +, *, -, /, %, &, and |.

The callable is stored by value. The left operand is stored as a reference when it is an lvalue and by value when it is an rvalue. The right operand is forwarded directly at the final invocation.

Template Parameters
FuncThe callable type.
Parameters
fThe callable object used by the named operator.
Returns
An internal token object that participates in named-operator syntax.
auto plus = gmp::make_named_operator([](int x, int y) {
return x + y;
});
int a = 10;
int b = 3;
auto r1 = a ^plus^ b; // 13
auto r2 = a <plus> b; // 13
auto add_assign = gmp::make_named_operator([](int& x, int y) -> int& {
x += y;
return x;
});
// add_assign can mutate the original lvalue.
int x = 1;
x ^add_assign^ 2; // x == 3
constexpr auto make_named_operator(Func &&f)
Create a token that lets a callable be used as a named infix operator.
consteval auto enum_values()
Get all enumerator values of an enumeration type at compile-time.
Definition meta.hpp:155
Examples
named_operator.cpp.

Definition at line 186 of file named_operator.hpp.

References gmp::enum_values().