Blender V5.0
BLI_struct_equality_utils.hh File Reference

Go to the source code of this file.

Macros

#define BLI_STRUCT_DERIVED_UNEQUAL_OPERATOR(Type)
#define BLI_STRUCT_EQUALITY_OPERATORS_1(Type, m)
#define BLI_STRUCT_EQUALITY_OPERATORS_2(Type, m1, m2)
#define BLI_STRUCT_EQUALITY_OPERATORS_3(Type, m1, m2, m3)
#define BLI_STRUCT_EQUALITY_OPERATORS_4(Type, m1, m2, m3, m4)
#define BLI_STRUCT_EQUALITY_OPERATORS_5(Type, m1, m2, m3, m4, m5)
#define BLI_STRUCT_EQUALITY_OPERATORS_6(Type, m1, m2, m3, m4, m5, m6)

Macro Definition Documentation

◆ BLI_STRUCT_DERIVED_UNEQUAL_OPERATOR

#define BLI_STRUCT_DERIVED_UNEQUAL_OPERATOR ( Type)
Value:
friend bool operator!=(const Type &a, const Type &b) \
{ \
return !(a == b); \
}
BLI_INLINE bool operator!=(const ListBase &a, const ListBase &b)

The macros below reduce the boilerplate needed to implement basic equality operators for structs. These macros could be removed starting with C++20, because then we can use defaulted comparison operators: https://en.cppreference.com/w/cpp/language/default_comparisons

Using these macros also reduces the probably for common typos, like comparing a value to itself or comparing the same value twice.

Definition at line 20 of file BLI_struct_equality_utils.hh.

◆ BLI_STRUCT_EQUALITY_OPERATORS_1

#define BLI_STRUCT_EQUALITY_OPERATORS_1 ( Type,
m )
Value:
friend bool operator==(const Type &a, const Type &b) \
{ \
return a.m == b.m; \
} \
BLI_STRUCT_DERIVED_UNEQUAL_OPERATOR(Type)
bool operator==(const AssetWeakReference &a, const AssetWeakReference &b)

Definition at line 26 of file BLI_struct_equality_utils.hh.

◆ BLI_STRUCT_EQUALITY_OPERATORS_2

#define BLI_STRUCT_EQUALITY_OPERATORS_2 ( Type,
m1,
m2 )
Value:
friend bool operator==(const Type &a, const Type &b) \
{ \
return a.m1 == b.m1 && a.m2 == b.m2; \
} \
BLI_STRUCT_DERIVED_UNEQUAL_OPERATOR(Type)

Definition at line 33 of file BLI_struct_equality_utils.hh.

◆ BLI_STRUCT_EQUALITY_OPERATORS_3

#define BLI_STRUCT_EQUALITY_OPERATORS_3 ( Type,
m1,
m2,
m3 )
Value:
friend bool operator==(const Type &a, const Type &b) \
{ \
return a.m1 == b.m1 && a.m2 == b.m2 && a.m3 == b.m3; \
} \
BLI_STRUCT_DERIVED_UNEQUAL_OPERATOR(Type)

Definition at line 40 of file BLI_struct_equality_utils.hh.

◆ BLI_STRUCT_EQUALITY_OPERATORS_4

#define BLI_STRUCT_EQUALITY_OPERATORS_4 ( Type,
m1,
m2,
m3,
m4 )
Value:
friend bool operator==(const Type &a, const Type &b) \
{ \
return a.m1 == b.m1 && a.m2 == b.m2 && a.m3 == b.m3 && a.m4 == b.m4; \
} \
BLI_STRUCT_DERIVED_UNEQUAL_OPERATOR(Type)

Definition at line 47 of file BLI_struct_equality_utils.hh.

◆ BLI_STRUCT_EQUALITY_OPERATORS_5

#define BLI_STRUCT_EQUALITY_OPERATORS_5 ( Type,
m1,
m2,
m3,
m4,
m5 )
Value:
friend bool operator==(const Type &a, const Type &b) \
{ \
return a.m1 == b.m1 && a.m2 == b.m2 && a.m3 == b.m3 && a.m4 == b.m4 && a.m5 == b.m5; \
} \
BLI_STRUCT_DERIVED_UNEQUAL_OPERATOR(Type)

Definition at line 54 of file BLI_struct_equality_utils.hh.

◆ BLI_STRUCT_EQUALITY_OPERATORS_6

#define BLI_STRUCT_EQUALITY_OPERATORS_6 ( Type,
m1,
m2,
m3,
m4,
m5,
m6 )
Value:
friend bool operator==(const Type &a, const Type &b) \
{ \
return a.m1 == b.m1 && a.m2 == b.m2 && a.m3 == b.m3 && a.m4 == b.m4 && a.m5 == b.m5 && \
a.m6 == b.m6; \
} \
BLI_STRUCT_DERIVED_UNEQUAL_OPERATOR(Type)

Definition at line 61 of file BLI_struct_equality_utils.hh.