Add compare operator to code generated for c++ (#4940)

* Add operator== for c++ genated code

New "--gen-compare" option for flatc to generate compare operators. The operators are defined based on object based api types.

Inspired by issue #263.

* Improve compare operator for c++.
Thanks for the code review.

- Improve robustness against future schema extensions
- Code style
- Fix --rust generation in generate_code.sh
This commit is contained in:
Thomas
2018-09-22 01:53:59 +02:00
committed by Wouter van Oortmerssen
parent 873a60b0d8
commit 33791dc7b0
11 changed files with 384 additions and 11 deletions

View File

@@ -1978,6 +1978,25 @@ void UninitializedVectorTest() {
TEST_EQ(test_1->b(), 40);
}
void EqualOperatorTest() {
MonsterT a;
MonsterT b;
TEST_EQ(b == a, true);
b.mana = 33;
TEST_EQ(b == a, false);
b.mana = 150;
TEST_EQ(b == a, true);
b.inventory.push_back(3);
TEST_EQ(b == a, false);
b.inventory.clear();
TEST_EQ(b == a, true);
b.test.type = Any_Monster;
TEST_EQ(b == a, false);
}
// For testing any binaries, e.g. from fuzzing.
void LoadVerifyBinaryTest() {
std::string binary;
@@ -2062,6 +2081,7 @@ int main(int /*argc*/, const char * /*argv*/ []) {
FlexBuffersTest();
UninitializedVectorTest();
EqualOperatorTest();
if (!testing_fails) {
TEST_OUTPUT_LINE("ALL TESTS PASSED");