// User-defined infix operator framework
template <typename LeftOperand, typename Operation>
struct LeftHelper
{
const LeftOperand& leftOperand;
const Operation& operation;
LeftHelper(const LeftOperand& leftOperand, const Operation& operation)
: leftOperand(leftOperand), operation(operation) {}
};
template <typename LeftOperand, typename Operation >
auto operator < (const LeftOperand& leftOperand, Operation& operation)
{
return LeftHelper<LeftOperand, Operation>(leftOperand, operation);
}
template <typename LeftOperand, typename Operation, typename RightOperand>
auto operator > (LeftHelper<LeftOperand, Operation> leftHelper, const RightOperand& rightOperand)
{
return leftHelper.operation(leftHelper.leftOperand, rightOperand);
}
// Defining a new operator
#include <cmath>
static auto pwr = [](const auto& operand1, const auto& operand2) { return std::pow(operand1, operand2); };
// using it
#include <iostream>
int main()
{
std::cout << (2 <pwr> 16) << std::endl;
return 0;
}
ICAgIC8vIFVzZXItZGVmaW5lZCBpbmZpeCBvcGVyYXRvciBmcmFtZXdvcmsKCiAgICB0ZW1wbGF0ZSA8dHlwZW5hbWUgTGVmdE9wZXJhbmQsIHR5cGVuYW1lIE9wZXJhdGlvbj4KICAgIHN0cnVjdCBMZWZ0SGVscGVyCiAgICB7CiAgICAgICAgY29uc3QgTGVmdE9wZXJhbmQmIGxlZnRPcGVyYW5kOwogICAgICAgIGNvbnN0IE9wZXJhdGlvbiYgb3BlcmF0aW9uOwogICAgICAgIExlZnRIZWxwZXIoY29uc3QgTGVmdE9wZXJhbmQmIGxlZnRPcGVyYW5kLCBjb25zdCBPcGVyYXRpb24mIG9wZXJhdGlvbikKICAgICAgICAgICAgOiBsZWZ0T3BlcmFuZChsZWZ0T3BlcmFuZCksIG9wZXJhdGlvbihvcGVyYXRpb24pIHt9CiAgICB9OwogICAgCiAgICB0ZW1wbGF0ZSA8dHlwZW5hbWUgTGVmdE9wZXJhbmQsIHR5cGVuYW1lIE9wZXJhdGlvbiA+CiAgICBhdXRvIG9wZXJhdG9yIDwgKGNvbnN0IExlZnRPcGVyYW5kJiBsZWZ0T3BlcmFuZCwgT3BlcmF0aW9uJ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