Class template operator_dispatch
Header:
proxy.h
Module:proxy
Namespace:pro::inline v4
The definition of operator_dispatch makes use of an exposition-only type string-literal, which is constructible from a char array at compile-time and can be used as a non-type template argument.
template <string-literal Sign, bool Rhs = false>
class operator_dispatch;
Class template operator_dispatch is a dispatch type for operator expressions. Sign represents the sign of operator (SOP) as a string literal (e.g., "+" for operator +). Rhs specifies whether the proxy operand is on the right-hand side of a binary operator.
Supported SOPs
As per C++20 specifications, there are 45 different SOPs. operator_dispatch supports the following 37 SOPs:
"+", "-", "*", "/", "%", "++", "--", "==", "!=", ">", "<", ">=", "<=", "<=>", "!", "&&", "||", "~", "&", "|", "^", "<<", ">>", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=", ",", "->*", "()", "[]"
The following 8 SOPs are not supported:
new,new[],delete,delete[], andco_awaitare context-dependent and not applicable forproxy.- Assignment (
=) and indirection (->) are ambiguous in the context ofproxy. - Literals (
"") apply only to a limited number of primitive types and are not applicable forproxy.
Type Conversion
Type conversion expressions, although using operator syntax, do not have a specific sign and are not within the scope of operator_dispatch. They are supported by class explicit_conversion_dispatch (aka. conversion_dispatch) and class implicit_conversion_dispatch.
Specializations
Let self be the operand of proxy, and other and others... be the other operand(s) in the expression of an operator. operator_dispatch has the following specializations for various expressions:
Member Functions
| Name | Description |
|---|---|
| (constructor) [nothrow] | constructs an operator_dispatch object |
operator() |
invokes the dispatch |
Member Types
Example
#include <iomanip>
#include <iostream>
#include <numbers>
#include <proxy/proxy.h>
struct Number : pro::facade_builder //
::add_convention<pro::operator_dispatch<"*=">, void(int)> //
::add_convention<pro::operator_dispatch<"<<", true>,
std::ostream&(std::ostream&) const&> //
::build {};
int main() {
pro::proxy<Number> p1 = pro::make_proxy<Number>(std::numbers::pi);
*p1 *= 3;
std::cout << std::setprecision(10) << *p1 << "\n"; // Prints: 9.424777961
pro::proxy<Number> p2 = pro::make_proxy<Number>(10);
*p2 *= 5;
std::cout << *p2 << "\n"; // Prints: 50
}
