Skip to content

Commit 1332662

Browse files
praihanmeta-codesync[bot]
authored andcommitted
Use C++20 features
Reviewed By: iahs Differential Revision: D87279282 fbshipit-source-id: a0dc9f5ae288853ca583516ffb55fa4e8bac667e
1 parent 90a4d19 commit 1332662

3 files changed

Lines changed: 0 additions & 65 deletions

File tree

third-party/thrift/src/thrift/compiler/whisker/ast.h

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ using bodies = std::vector<body>;
6969
using header = std::variant<comment, pragma_statement, import_statement>;
7070
using headers = std::vector<header>;
7171

72-
// Defines operator!= in terms of operator==
73-
// Remove in C++20 which introduces comparison operator synthesis
74-
#define WHISKER_DEFINE_OPERATOR_INEQUALITY(type) \
75-
friend bool operator!=(const type& lhs, const type& rhs) { \
76-
return !(lhs == rhs); \
77-
}
78-
7972
/**
8073
* The root node of a Whisker AST representing a source file.
8174
*/
@@ -154,8 +147,6 @@ struct identifier {
154147
friend bool operator==(const identifier& lhs, const identifier& rhs) {
155148
return lhs.name == rhs.name;
156149
}
157-
// Remove in C++20 which introduces comparison operator synthesis
158-
WHISKER_DEFINE_OPERATOR_INEQUALITY(identifier)
159150

160151
// For std::map and std::set
161152
struct compare_by_name {
@@ -195,8 +186,6 @@ struct variable_component {
195186
const variable_component& lhs, const variable_component& rhs) {
196187
return lhs.qualifier == rhs.qualifier && lhs.property == rhs.property;
197188
}
198-
// Remove in C++20 which introduces comparison operator synthesis
199-
WHISKER_DEFINE_OPERATOR_INEQUALITY(variable_component)
200189

201190
/**
202191
* Returns a source-identical string representation of this variable
@@ -221,9 +210,7 @@ struct variable_lookup {
221210
source_range loc;
222211
// this_ref is a special case: {{.}} referring to the current object.
223212
struct this_ref {
224-
// Remove in C++20 which introduces comparison operator synthesis
225213
friend bool operator==(const this_ref&, const this_ref&) { return true; }
226-
WHISKER_DEFINE_OPERATOR_INEQUALITY(this_ref)
227214
};
228215
std::variant<this_ref, std::vector<variable_component>> chain;
229216

@@ -235,8 +222,6 @@ struct variable_lookup {
235222
const variable_lookup& lhs, const variable_lookup& rhs) {
236223
return lhs.chain == rhs.chain;
237224
}
238-
// Remove in C++20 which introduces comparison operator synthesis
239-
WHISKER_DEFINE_OPERATOR_INEQUALITY(variable_lookup)
240225

241226
std::string chain_string() const;
242227
};
@@ -266,44 +251,36 @@ struct expression {
266251
* The `(not arg1)` function.
267252
*/
268253
struct builtin_not : builtin {
269-
// Remove in C++20 which introduces comparison operator synthesis
270254
friend bool operator==(const builtin_not&, const builtin_not&) {
271255
return true;
272256
}
273-
WHISKER_DEFINE_OPERATOR_INEQUALITY(builtin_not)
274257
};
275258

276259
/**
277260
* The `(and arg1 ... argN)` function.
278261
*/
279262
struct builtin_and : builtin, builtin_binary_associative {
280-
// Remove in C++20 which introduces comparison operator synthesis
281263
friend bool operator==(const builtin_and&, const builtin_and&) {
282264
return true;
283265
}
284-
WHISKER_DEFINE_OPERATOR_INEQUALITY(builtin_and)
285266
};
286267

287268
/**
288269
* The `(or arg1 ... argN)` function.
289270
*/
290271
struct builtin_or : builtin, builtin_binary_associative {
291-
// Remove in C++20 which introduces comparison operator synthesis
292272
friend bool operator==(const builtin_or&, const builtin_or&) {
293273
return true;
294274
}
295-
WHISKER_DEFINE_OPERATOR_INEQUALITY(builtin_or)
296275
};
297276

298277
/**
299278
* The `(if cond true_val false_val)` ternary function.
300279
*/
301280
struct builtin_ternary : builtin {
302-
// Remove in C++20 which introduces comparison operator synthesis
303281
friend bool operator==(const builtin_ternary&, const builtin_ternary&) {
304282
return true;
305283
}
306-
WHISKER_DEFINE_OPERATOR_INEQUALITY(builtin_ternary)
307284
};
308285

309286
/**
@@ -319,8 +296,6 @@ struct expression {
319296
friend bool operator==(const user_defined& lhs, const user_defined& rhs) {
320297
return lhs.name == rhs.name;
321298
}
322-
// Remove in C++20 which introduces comparison operator synthesis
323-
WHISKER_DEFINE_OPERATOR_INEQUALITY(user_defined)
324299
};
325300

326301
std::variant<
@@ -350,8 +325,6 @@ struct expression {
350325
};
351326
return as_tuple(lhs) == as_tuple(rhs);
352327
}
353-
// Remove in C++20 which introduces comparison operator synthesis
354-
WHISKER_DEFINE_OPERATOR_INEQUALITY(named_argument)
355328
};
356329
/**
357330
* Named arguments that are identified by their name, with no restrictions
@@ -374,8 +347,6 @@ struct expression {
374347
};
375348
return as_tuple(lhs) == as_tuple(rhs);
376349
}
377-
// Remove in C++20 which introduces comparison operator synthesis
378-
WHISKER_DEFINE_OPERATOR_INEQUALITY(function_call)
379350
};
380351

381352
struct string_literal {
@@ -385,8 +356,6 @@ struct expression {
385356
const string_literal& lhs, const string_literal& rhs) {
386357
return lhs.text == rhs.text;
387358
}
388-
// Remove in C++20 which introduces comparison operator synthesis
389-
WHISKER_DEFINE_OPERATOR_INEQUALITY(string_literal)
390359
};
391360

392361
struct i64_literal {
@@ -395,32 +364,24 @@ struct expression {
395364
friend bool operator==(const i64_literal& lhs, const i64_literal& rhs) {
396365
return lhs.value == rhs.value;
397366
}
398-
// Remove in C++20 which introduces comparison operator synthesis
399-
WHISKER_DEFINE_OPERATOR_INEQUALITY(i64_literal)
400367
};
401368

402369
struct null_literal {
403370
friend bool operator==(const null_literal&, const null_literal&) {
404371
return true;
405372
}
406-
// Remove in C++20 which introduces comparison operator synthesis
407-
WHISKER_DEFINE_OPERATOR_INEQUALITY(null_literal)
408373
};
409374

410375
struct true_literal {
411376
friend bool operator==(const true_literal&, const true_literal&) {
412377
return true;
413378
}
414-
// Remove in C++20 which introduces comparison operator synthesis
415-
WHISKER_DEFINE_OPERATOR_INEQUALITY(true_literal)
416379
};
417380

418381
struct false_literal {
419382
friend bool operator==(const false_literal&, const false_literal&) {
420383
return true;
421384
}
422-
// Remove in C++20 which introduces comparison operator synthesis
423-
WHISKER_DEFINE_OPERATOR_INEQUALITY(false_literal)
424385
};
425386

426387
std::variant<
@@ -440,8 +401,6 @@ struct expression {
440401
friend bool operator==(const expression& lhs, const expression& rhs) {
441402
return lhs.which == rhs.which;
442403
}
443-
// Remove in C++20 which introduces comparison operator synthesis
444-
WHISKER_DEFINE_OPERATOR_INEQUALITY(expression)
445404

446405
/**
447406
* Returns a human-readable text representation of the expression.

third-party/thrift/src/thrift/compiler/whisker/expected.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -687,23 +687,6 @@ class expected {
687687
return !lhs.has_value() && lhs.error() == rhs.error();
688688
}
689689

690-
// Before C++20, operator!= is not synthesized from operator==.
691-
template <
692-
typename U,
693-
typename G,
694-
std::enable_if_t<!std::is_void_v<U>, int> = 0>
695-
friend bool operator!=(const expected<T, E>& lhs, const expected<U, G>& rhs) {
696-
return !(lhs == rhs);
697-
}
698-
template <typename T2>
699-
friend bool operator!=(const expected<T, E>& lhs, const T2& rhs) {
700-
return !(lhs == rhs);
701-
}
702-
template <typename E2>
703-
friend bool operator!=(const expected<T, E>& lhs, const unexpected<E2>& rhs) {
704-
return !(lhs == rhs);
705-
}
706-
707690
private:
708691
template <typename U, typename G>
709692
friend class expected;

third-party/thrift/src/thrift/compiler/whisker/token.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,7 @@ struct token_kind {
170170
friend bool operator==(token_kind lhs, token_kind rhs) {
171171
return lhs.value == rhs.value;
172172
}
173-
174-
// The following overloads are only for compatibility with pre-C++20.
175173
friend bool operator==(token_kind lhs, tok rhs) { return lhs.value == rhs; }
176-
friend bool operator!=(tok lhs, token_kind rhs) { return lhs != rhs.value; }
177-
friend bool operator!=(token_kind lhs, tok rhs) { return lhs.value != rhs; }
178-
friend bool operator!=(token_kind lhs, token_kind rhs) {
179-
return lhs.value != rhs.value;
180-
}
181174
};
182175

183176
std::string_view to_string(token_kind kind);

0 commit comments

Comments
 (0)