24 std::string
toString()
const {
return "[" + std::to_string(
x) +
", " + std::to_string(
y) +
"]"; }
48 return x == v.
x &&
y == v.
y;
51 return x != v.
x ||
y != v.
y;
80 return "abs(Vector2)";
85 #pragma GCC diagnostic push 91 #if defined(__APPLE__) && defined(__clang__) 92 #if (__clang_major__ >= 10) && (__clang_minor__ >= 0) && (__clang_patchlevel__ >= 1) 93 #pragma GCC diagnostic ignored "-Wself-assign-overloaded" 95 #elif defined(__clang__) 96 #if (__clang_major__ >= 7) 97 #pragma GCC diagnostic ignored "-Wself-assign-overloaded" 105 py::class_<Vector2>(
m,
"Vector2")
106 .def(py::init<float, float>())
114 .def(py::self / py::self)
115 .def(py::self += py::self)
116 .def(py::self -= py::self)
117 .def(py::self *=
float())
118 .def(py::self /=
float())
119 .def(py::self *= py::self)
120 .def(py::self /= py::self)
121 .def(
float() + py::self)
122 .def(
float() - py::self)
123 .def(
float() * py::self)
124 .def(
float() / py::self)
128 .def(py::self == py::self)
129 .def(py::self != py::self)
133 .def(
"__abs__", [](
const Vector2&
v) {
return abs(v); })
136 m.attr(
"Vector") = m.attr(
"Vector2");
140 py::class_<C1>(
m,
"C1")
142 .def(py::self + py::self);
144 py::class_<C2>(
m,
"C2")
146 .def(py::self + py::self)
147 .def(
"__add__", [](
const C2&
c2,
const C1&
c1) {
return c2 +
c1; })
148 .def(
"__radd__", [](
const C2& c2,
const C1& c1) {
return c1 +
c2; });
152 struct NestABase {
int value = -2; };
153 py::class_<NestABase>(
m,
"NestABase")
157 struct NestA : NestABase {
161 py::class_<NestA>(
m,
"NestA")
163 .def(py::self +=
int())
164 .def(
"as_base", [](NestA &
a) -> NestABase& {
165 return (NestABase&)
a;
166 }, py::return_value_policy::reference_internal);
167 m.def(
"get_NestA", [](
const NestA &a) {
return a.value; });
174 py::class_<NestB>(
m,
"NestB")
176 .def(py::self -=
int())
178 m.def(
"get_NestB", [](
const NestB &
b) {
return b.value; });
185 py::class_<NestC>(
m,
"NestC")
187 .def(py::self *=
int())
189 m.def(
"get_NestC", [](
const NestC &
c) {
return c.value; });
196 bool operator==(
const Comparable& rhs)
const {
return value == rhs.value;}
199 struct Hashable : Comparable {
200 explicit Hashable(
int value): Comparable{value}{};
201 size_t hash()
const {
return static_cast<size_t>(
value); }
204 struct Hashable2 : Hashable {
205 using Hashable::Hashable;
208 py::class_<Comparable>(
m,
"Comparable")
209 .def(py::init<int>())
210 .def(py::self == py::self);
212 py::class_<Hashable>(
m,
"Hashable")
213 .def(py::init<int>())
214 .def(py::self == py::self)
218 py::class_<Hashable2>(
m,
"Hashable2")
220 .def(py::init<int>())
221 .def(py::self == py::self);
225 #pragma GCC diagnostic pop
Vector2 & operator/=(const Vector2 &v)
Vector2 operator*(float value) const
Vector2 operator+(float value) const
Vector2 & operator*=(const Vector2 &v)
Vector2 operator*(const Vector2 &v) const
friend Vector2 operator-(float f, const Vector2 &v)
void print_destroyed(T *inst, Values &&...values)
bool operator==(const Vector2 &v) const
std::string toString() const
void print_copy_assigned(T *inst, Values &&...values)
void print_copy_created(T *inst, Values &&...values)
Vector2(float x, float y)
Vector2 & operator+=(const Vector2 &v)
Vector2 operator+(const Vector2 &v) const
Vector2 & operator=(Vector2 &&v)
void print_move_assigned(T *inst, Values &&...values)
Vector2 & operator-=(const Vector2 &v)
Vector2 operator/(float value) const
Vector2 & operator=(const Vector2 &v)
TEST_SUBMODULE(operators, m)
Vector2 & operator/=(float v)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Vector2 operator-(const Vector2 &v) const
std::string abs(const Vector2 &)
friend Vector2 operator/(float f, const Vector2 &v)
Vector2 operator-() const
friend Vector2 operator+(float f, const Vector2 &v)
Vector2 operator/(const Vector2 &v) const
friend Vector2 operator*(float f, const Vector2 &v)
size_t operator()(const Vector2 &)
void print_created(T *inst, Values &&...values)
Vector2 & operator*=(float v)
bool operator!=(const Vector2 &v) const
Vector2(const Vector2 &v)
void print_move_created(T *inst, Values &&...values)
Vector2 operator-(float value) const