Skip to content

Commit 6b22b3d

Browse files
committed
Add rvalue versions to API set() macros. cherry-pick:main
1 parent 03ff4fd commit 6b22b3d

1 file changed

Lines changed: 32 additions & 17 deletions

File tree

libraries/API/include/api/macros.hpp

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,36 @@ private: \
6363
#define API_AF(c, t, v, iv) API_ACCESS_FUNDAMENTAL(c, t, v, iv)
6464

6565
#define API_PUBLIC_MEMBER(CLASS, TYPE, NAME, INITIAL_VALUE) \
66-
CLASS &set_##NAME(TYPE value_parameter) { \
66+
CLASS &set_##NAME(TYPE value_parameter) & { \
6767
NAME = value_parameter; \
6868
return *this; \
6969
} \
70-
\
70+
CLASS &&set_##NAME(TYPE value_parameter) && { \
71+
return std::move(set_##NAME(value_parameter)); \
72+
} \
7173
TYPE NAME = INITIAL_VALUE
7274

7375
#define API_PUBLIC_MEMBER_AZ(NAME, CLASS, TYPE, INITIAL_VALUE) \
74-
CLASS &set_##NAME(TYPE value_parameter) { \
76+
CLASS &set_##NAME(TYPE value_parameter) & { \
7577
NAME = value_parameter; \
7678
return *this; \
7779
} \
78-
\
80+
CLASS &&set_##NAME(TYPE value_parameter) && { \
81+
return std::move(set_##NAME(value_parameter)); \
82+
} \
7983
TYPE NAME = INITIAL_VALUE
8084

8185
#define API_PMAZ(NAME, CLASS, TYPE, INITIAL_VALUE) \
8286
API_PUBLIC_MEMBER_AZ(NAME, CLASS, TYPE, INITIAL_VALUE)
8387

8488
#define API_PUBLIC_BOOL(CLASS, NAME, INITIAL_VALUE) \
85-
CLASS &set_##NAME(bool value_parameter = true) { \
89+
CLASS &set_##NAME(bool value_parameter = true) & { \
8690
is_##NAME = value_parameter; \
8791
return *this; \
8892
} \
89-
\
93+
CLASS &&set_##NAME(bool value_parameter = true) && { \
94+
return std::move(set_##NAME(value_parameter)); \
95+
} \
9096
bool is_##NAME = INITIAL_VALUE
9197

9298
#define API_ACCESS_MEMBER_FUNDAMENTAL(c, t, p, v) \
@@ -108,21 +114,23 @@ public: \
108114
#define API_ACCESS_MEMBER_FUNDAMENTAL_WITH_ALIAS(c, t, p, a, v) \
109115
public: \
110116
API_NO_DISCARD t a() const { return m_##p.v; } \
111-
c &set_##a(t value) { \
117+
c &set_##a(t value) & { \
112118
m_##p.v = value; \
113119
return *this; \
114-
}
120+
} \
121+
c &&set_##a(t value) && { return std::move(set_##a(value)); }
115122

116123
#define API_AMFWA(c, t, p, a, v) \
117124
API_ACCESS_MEMBER_FUNDAMENTAL_WITH_ALIAS(c, t, p, a, v)
118125

119126
#define API_ACCESS_MEMBER_COMPOUND(c, t, p, v) \
120127
public: \
121128
API_NO_DISCARD const t &v() const { return m_##p.v; } \
122-
c &set_##v(const t &value) { \
129+
c &set_##v(const t &value) & { \
123130
m_##p.v = value; \
124131
return *this; \
125-
}
132+
} \
133+
c &&set_##v(const t &value) && { return std::move(set_##v(value)); }
126134

127135
#define API_AMC(c, t, p, v) API_ACCESS_MEMBER_COMPOUND(c, t, p, v)
128136

@@ -139,10 +147,11 @@ private: \
139147
public: \
140148
API_NO_DISCARD const t &v() const { return m_##v; } \
141149
t &v() { return m_##v; } \
142-
c &set_##v(const t &value) { \
150+
c &set_##v(const t &value) & { \
143151
m_##v = value; \
144152
return *this; \
145153
} \
154+
c &&set_##v(const t &value) && { return std::move(set_##v(value)); } \
146155
\
147156
private: \
148157
t m_##v
@@ -154,9 +163,12 @@ public: \
154163
API_NO_DISCARD var::StringView VALUE_NAME() const { \
155164
return m_##VALUE_NAME.string_view(); \
156165
} \
157-
PARENT_VALUE &set_##VALUE_NAME(const var::StringView value) { \
166+
PARENT_VALUE &set_##VALUE_NAME(const var::StringView value) & { \
158167
m_##VALUE_NAME = value.to_string(); \
159168
return *this; \
169+
} \
170+
PARENT_VALUE &&set_##VALUE_NAME(const var::StringView value) && { \
171+
return std::move(set_##VALUE_NAME(value)); \
160172
} \
161173
\
162174
private: \
@@ -175,26 +187,29 @@ private: \
175187
#define API_RAC(c, t, v) API_READ_ACCESS_COMPOUND(c, t, v)
176188

177189
#define API_ACCESS_DERIVED_COMPOUND(c, d, t, v) \
178-
d &set_##v(const t &value) { \
190+
d &set_##v(const t &value) & { \
179191
c::set_##v(value); \
180192
return static_cast<d &>(*this); \
181-
}
193+
} \
194+
d &&set_##v(const t &value) && { return std::move(set_##v(value)); }
182195

183196
#define API_ADC(c, d, t, v) API_ACCESS_DERIVED_COMPOUND(c, d, t, v)
184197

185198
#define API_ACCESS_DERIVED_FUNDAMETAL(c, d, t, v) \
186-
d &set_##v(t value) { \
199+
d &set_##v(t value) & { \
187200
c::set_##v(value); \
188201
return static_cast<d &>(*this); \
189-
}
202+
} \
203+
d &&set_##v(t value) && { return std::move(set_##v(value)); }
190204

191205
#define API_ADF(c, d, t, v) API_ACCESS_DERIVED_FUNDAMETAL(c, d, t, v)
192206

193207
#define API_ACCESS_DERIVED_BOOL(c, d, v) \
194208
d &set_##v(bool value = true) { \
195209
c::set_##v(value); \
196210
return static_cast<d &>(*this); \
197-
}
211+
} \
212+
d &&set_##v(bool value = true) && { return std::move(set_##v(value)); }
198213

199214
#define API_ADB(c, d, v) API_ACCESS_DERIVED_BOOL(c, d, v)
200215

0 commit comments

Comments
 (0)