welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
Loading...
Searching...
No Matches
operators.hpp
Go to the documentation of this file.
1#pragma once
2#include <meta>
3
4#include <welder/bind_traits.hpp> // is_unary_operator
5
21
22namespace welder::inline v0::rods::python {
23
39consteval const char* operator_dunder(std::meta::info f) {
40 using std::meta::operators;
41 const bool unary{::welder::detail::is_unary_operator(f)};
42 switch (std::meta::operator_of(f)) {
43 case operators::op_plus: return unary ? "__pos__" : "__add__";
44 case operators::op_minus: return unary ? "__neg__" : "__sub__";
45 case operators::op_star: return unary ? nullptr : "__mul__"; // unary * = deref
46 case operators::op_slash: return "__truediv__";
47 case operators::op_percent: return "__mod__";
48 case operators::op_tilde: return "__invert__";
49 case operators::op_caret: return "__xor__";
50 case operators::op_ampersand: return unary ? nullptr : "__and__"; // unary & = address-of
51 case operators::op_pipe: return "__or__";
52 case operators::op_less_less: return "__lshift__";
53 case operators::op_greater_greater: return "__rshift__";
54 case operators::op_equals_equals: return "__eq__";
55 case operators::op_exclamation_equals: return "__ne__";
56 case operators::op_less: return "__lt__";
57 case operators::op_greater: return "__gt__";
58 case operators::op_less_equals: return "__le__";
59 case operators::op_greater_equals: return "__ge__";
60 case operators::op_parentheses: return "__call__";
61 case operators::op_square_brackets: return "__getitem__";
62 default: return nullptr;
63 }
64}
65
66} // namespace welder::rods::python
Backend-agnostic selection layer: the reflection predicates and selectors that decide what participat...
consteval bool is_unary_operator(std::meta::info f)
Whether a member operator is unary (0 parameters) vs binary (1 parameter).
consteval const char * operator_dunder(std::meta::info f)
The Python special-method ("dunder") name for a member operator, or nullptr if welder does not expose...
Definition operators.hpp:39