GMP 0.3.0
Generative Metaprogramming library for C++
Loading...
Searching...
No Matches
named_operator.cpp

Build and use custom infix-style operators. Demonstrates how make_named_operator can wrap callables and expose them through the custom infix syntax supported by GMP.

#include <gmp/gmp.hpp>
int main() {
auto plus = gmp::make_named_operator([](int lhs, int rhs) {
return lhs + rhs;
});
auto add_assign = gmp::make_named_operator([](int& lhs, int rhs) -> int& {
lhs += rhs;
return lhs;
});
int value = 10;
const int result = value ^plus^ 5;
value ^add_assign^ 7;
return (result == 15 && value == 17) ? 0 : 1;
}
constexpr auto make_named_operator(Func &&f)
Create a token that lets a callable be used as a named infix operator.