From db61fc9a8212173dfe61b1b10fb18d4c3a448f52 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Wed, 30 Nov 2022 06:47:56 +0000 Subject: [PATCH 01/23] update unit test and generated file to test is extra endianswap can help resolve issue --- tests/key_field/key_field_sample_generated.h | 16 +++++----- tests/key_field_test.cpp | 31 +++++++++++++------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index 1bcb897624c..da9500afb66 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -67,11 +67,11 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { bool KeyCompareLessThan(const Baz * const o) const { return KeyCompareWithValue(o->a()) < 0; } - int KeyCompareWithValue(const flatbuffers::Array *_a) const { + int KeyCompareWithValue(const flatbuffers::Array *_a) const { for (auto i = 0; i < a()->size(); i++) { - const auto a_l = a_[i]; - const auto a_r = _a->Get(i); - if(a_l != a_r) + const auto a_l = flatbuffers::EndianScalar(a_[i]); + const auto a_r = flatbuffers::EndianScalar(_a->Get(i)); + if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); } return 0; @@ -139,11 +139,11 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { bool KeyCompareLessThan(const Bar * const o) const { return KeyCompareWithValue(o->a()) < 0; } - int KeyCompareWithValue(const flatbuffers::Array *_a) const { + int KeyCompareWithValue(const flatbuffers::Array *_a) const { for (auto i = 0; i < a()->size(); i++) { - const auto a_l = a_[i]; - const auto a_r = _a->Get(i); - if(a_l != a_r) + const auto a_l = flatbuffers::EndianScalar(a_[i]); + const auto a_r = flatbuffers::EndianScalar(_a->Get(i)); + if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); } return 0; diff --git a/tests/key_field_test.cpp b/tests/key_field_test.cpp index b2bf0af91ea..6814bb43b81 100644 --- a/tests/key_field_test.cpp +++ b/tests/key_field_test.cpp @@ -24,7 +24,9 @@ void FixedSizedScalarKeyInStructTest() { bazs.push_back(Baz(flatbuffers::make_span(test_array3), 2)); bazs.push_back(Baz(flatbuffers::make_span(test_array4), 3)); auto baz_vec = fbb.CreateVectorOfSortedStructs(&bazs); + auto test_string = fbb.CreateString("TEST"); + float test_float_array1[3] = { 1.5, 2.5, 0 }; float test_float_array2[3] = { 7.5, 2.5, 0 }; float test_float_array3[3] = { 1.5, 2.5, -1 }; @@ -36,6 +38,7 @@ void FixedSizedScalarKeyInStructTest() { bars.push_back(Bar(flatbuffers::make_span(test_float_array4), 1)); auto bar_vec = fbb.CreateVectorOfSortedStructs(&bars); + auto t = CreateFooTable(fbb, 1, 2, test_string, baz_vec, bar_vec); fbb.Finish(t); @@ -45,26 +48,34 @@ void FixedSizedScalarKeyInStructTest() { auto sorted_baz_vec = foo_table->d(); TEST_EQ(sorted_baz_vec->Get(0)->b(), 1); TEST_EQ(sorted_baz_vec->Get(3)->b(), 4); + + uint8_t test_array[4]; + auto key_array = &flatbuffers::CastToArray(test_array); + key_array->CopyFromSpan(flatbuffers::make_span(test_array1)); + + TEST_NOTNULL( - sorted_baz_vec->LookupByKey(&flatbuffers::CastToArray(test_array1))); + sorted_baz_vec->LookupByKey(key_array)); TEST_EQ( - sorted_baz_vec->LookupByKey(&flatbuffers::CastToArray(test_array1))->b(), + sorted_baz_vec->LookupByKey(key_array)->b(), 4); uint8_t array_int[4] = { 7, 2, 3, 0 }; - TEST_EQ(sorted_baz_vec->LookupByKey(&flatbuffers::CastToArray(array_int)), + key_array->CopyFromSpan(flatbuffers::make_span(array_int)); + TEST_EQ(sorted_baz_vec->LookupByKey(key_array), static_cast(nullptr)); auto sorted_bar_vec = foo_table->e(); TEST_EQ(sorted_bar_vec->Get(0)->b(), 1); TEST_EQ(sorted_bar_vec->Get(3)->b(), 4); - TEST_NOTNULL(sorted_bar_vec->LookupByKey( - &flatbuffers::CastToArray(test_float_array1))); - TEST_EQ( - sorted_bar_vec->LookupByKey(&flatbuffers::CastToArray(test_float_array1)) - ->b(), - 3); + + float test_float_array[3]; + auto key_float_array = &flatbuffers::CastToArray(test_float_array); + key_float_array->CopyFromSpan(flatbuffers::make_span(test_float_array1)); + TEST_NOTNULL(sorted_bar_vec->LookupByKey(key_float_array)); + TEST_EQ(sorted_bar_vec->LookupByKey(key_float_array)->b(), 3); float array_float[3] = { -1, -2, -3 }; - TEST_EQ(sorted_bar_vec->LookupByKey(&flatbuffers::CastToArray(array_float)), + key_float_array->CopyFromSpan(flatbuffers::make_span(array_float)); + TEST_EQ(sorted_bar_vec->LookupByKey(key_float_array), static_cast(nullptr)); } From 5bad57961292c0792bb2ea7cd94a6910a0be2d55 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Thu, 1 Dec 2022 05:54:18 +0000 Subject: [PATCH 02/23] remove EndianScalar wrapper from Get method --- tests/key_field/key_field_sample_generated.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index da9500afb66..407272d7bb1 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -70,7 +70,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { int KeyCompareWithValue(const flatbuffers::Array *_a) const { for (auto i = 0; i < a()->size(); i++) { const auto a_l = flatbuffers::EndianScalar(a_[i]); - const auto a_r = flatbuffers::EndianScalar(_a->Get(i)); + const auto a_r = _a->Get(i); if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); } From 32f6e7252be92318d74b65b37997c779971ebed5 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Fri, 2 Dec 2022 04:40:42 +0000 Subject: [PATCH 03/23] remove endianscalar wrapper --- tests/key_field/key_field_sample_generated.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index 407272d7bb1..2c2ff743faf 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -141,7 +141,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { } int KeyCompareWithValue(const flatbuffers::Array *_a) const { for (auto i = 0; i < a()->size(); i++) { - const auto a_l = flatbuffers::EndianScalar(a_[i]); + const auto a_l = a_[i]; const auto a_r = flatbuffers::EndianScalar(_a->Get(i)); if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); From 9d661e7b5776e381a7418d18f7c97227995108f7 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Fri, 2 Dec 2022 06:45:56 +0000 Subject: [PATCH 04/23] update --- src/idl_gen_cpp.cpp | 2 +- tests/key_field/key_field_sample_generated.h | 223 +------------------ 2 files changed, 3 insertions(+), 222 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index e3d1ff35b41..a4706e663ad 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2310,7 +2310,7 @@ class CppGenerator : public BaseGenerator { " int KeyCompareWithValue(const {{INPUT_TYPE}} *_{{FIELD_NAME}}" ") const { "; code_ += " for (auto i = 0; i < {{FIELD_NAME}}()->size(); i++) {"; - code_ += " const auto {{FIELD_NAME}}_l = {{FIELD_NAME}}_[i];"; + code_ += " const auto {{FIELD_NAME}}_l = flatbuffers::EndianScalar({{FIELD_NAME}}_[i]);"; code_ += " const auto {{FIELD_NAME}}_r = _{{FIELD_NAME}}->Get(i);"; code_ += " if({{FIELD_NAME}}_l != {{FIELD_NAME}}_r) "; code_ += diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index 2c2ff743faf..a436afd861f 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -22,20 +22,6 @@ struct Bar; struct FooTable; struct FooTableBuilder; -struct FooTableT; - -bool operator==(const Baz &lhs, const Baz &rhs); -bool operator!=(const Baz &lhs, const Baz &rhs); -bool operator==(const Bar &lhs, const Bar &rhs); -bool operator!=(const Bar &lhs, const Bar &rhs); -bool operator==(const FooTableT &lhs, const FooTableT &rhs); -bool operator!=(const FooTableT &lhs, const FooTableT &rhs); - -inline const flatbuffers::TypeTable *BazTypeTable(); - -inline const flatbuffers::TypeTable *BarTypeTable(); - -inline const flatbuffers::TypeTable *FooTableTypeTable(); FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { private: @@ -43,9 +29,6 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { uint8_t b_; public: - static const flatbuffers::TypeTable *MiniReflectTypeTable() { - return BazTypeTable(); - } Baz() : a_(), b_(0) { @@ -61,9 +44,6 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { const flatbuffers::Array *a() const { return &flatbuffers::CastToArray(a_); } - flatbuffers::Array *mutable_a() { - return &flatbuffers::CastToArray(a_); - } bool KeyCompareLessThan(const Baz * const o) const { return KeyCompareWithValue(o->a()) < 0; } @@ -79,23 +59,9 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { uint8_t b() const { return flatbuffers::EndianScalar(b_); } - void mutate_b(uint8_t _b) { - flatbuffers::WriteScalar(&b_, _b); - } }; FLATBUFFERS_STRUCT_END(Baz, 5); -inline bool operator==(const Baz &lhs, const Baz &rhs) { - return - (lhs.a() == rhs.a()) && - (lhs.b() == rhs.b()); -} - -inline bool operator!=(const Baz &lhs, const Baz &rhs) { - return !(lhs == rhs); -} - - FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { private: float a_[3]; @@ -103,9 +69,6 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { int8_t padding0__; int16_t padding1__; public: - static const flatbuffers::TypeTable *MiniReflectTypeTable() { - return BarTypeTable(); - } Bar() : a_(), b_(0), @@ -133,16 +96,13 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { const flatbuffers::Array *a() const { return &flatbuffers::CastToArray(a_); } - flatbuffers::Array *mutable_a() { - return &flatbuffers::CastToArray(a_); - } bool KeyCompareLessThan(const Bar * const o) const { return KeyCompareWithValue(o->a()) < 0; } int KeyCompareWithValue(const flatbuffers::Array *_a) const { for (auto i = 0; i < a()->size(); i++) { - const auto a_l = a_[i]; - const auto a_r = flatbuffers::EndianScalar(_a->Get(i)); + const auto a_l = flatbuffers::(a_[i]); + const auto a_r = _a->Get(i); if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); } @@ -151,38 +111,11 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { uint8_t b() const { return flatbuffers::EndianScalar(b_); } - void mutate_b(uint8_t _b) { - flatbuffers::WriteScalar(&b_, _b); - } }; FLATBUFFERS_STRUCT_END(Bar, 16); -inline bool operator==(const Bar &lhs, const Bar &rhs) { - return - (lhs.a() == rhs.a()) && - (lhs.b() == rhs.b()); -} - -inline bool operator!=(const Bar &lhs, const Bar &rhs) { - return !(lhs == rhs); -} - - -struct FooTableT : public flatbuffers::NativeTable { - typedef FooTable TableType; - int32_t a = 0; - int32_t b = 0; - std::string c{}; - std::vector d{}; - std::vector e{}; -}; - struct FooTable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - typedef FooTableT NativeTableType; typedef FooTableBuilder Builder; - static const flatbuffers::TypeTable *MiniReflectTypeTable() { - return FooTableTypeTable(); - } enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_A = 4, VT_B = 6, @@ -193,21 +126,12 @@ struct FooTable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { int32_t a() const { return GetField(VT_A, 0); } - bool mutate_a(int32_t _a = 0) { - return SetField(VT_A, _a, 0); - } int32_t b() const { return GetField(VT_B, 0); } - bool mutate_b(int32_t _b = 0) { - return SetField(VT_B, _b, 0); - } const flatbuffers::String *c() const { return GetPointer(VT_C); } - flatbuffers::String *mutable_c() { - return GetPointer(VT_C); - } bool KeyCompareLessThan(const FooTable * const o) const { return *c() < *o->c(); } @@ -217,15 +141,9 @@ struct FooTable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { const flatbuffers::Vector *d() const { return GetPointer *>(VT_D); } - flatbuffers::Vector *mutable_d() { - return GetPointer *>(VT_D); - } const flatbuffers::Vector *e() const { return GetPointer *>(VT_E); } - flatbuffers::Vector *mutable_e() { - return GetPointer *>(VT_E); - } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, VT_A, 4) && @@ -238,9 +156,6 @@ struct FooTable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { verifier.VerifyVector(e()) && verifier.EndTable(); } - FooTableT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; - void UnPackTo(FooTableT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; - static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const FooTableT* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); }; struct FooTableBuilder { @@ -309,120 +224,6 @@ inline flatbuffers::Offset CreateFooTableDirect( e__); } -flatbuffers::Offset CreateFooTable(flatbuffers::FlatBufferBuilder &_fbb, const FooTableT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); - - -inline bool operator==(const FooTableT &lhs, const FooTableT &rhs) { - return - (lhs.a == rhs.a) && - (lhs.b == rhs.b) && - (lhs.c == rhs.c) && - (lhs.d == rhs.d) && - (lhs.e == rhs.e); -} - -inline bool operator!=(const FooTableT &lhs, const FooTableT &rhs) { - return !(lhs == rhs); -} - - -inline FooTableT *FooTable::UnPack(const flatbuffers::resolver_function_t *_resolver) const { - auto _o = std::unique_ptr(new FooTableT()); - UnPackTo(_o.get(), _resolver); - return _o.release(); -} - -inline void FooTable::UnPackTo(FooTableT *_o, const flatbuffers::resolver_function_t *_resolver) const { - (void)_o; - (void)_resolver; - { auto _e = a(); _o->a = _e; } - { auto _e = b(); _o->b = _e; } - { auto _e = c(); if (_e) _o->c = _e->str(); } - { auto _e = d(); if (_e) { _o->d.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->d[_i] = *_e->Get(_i); } } else { _o->d.resize(0); } } - { auto _e = e(); if (_e) { _o->e.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->e[_i] = *_e->Get(_i); } } else { _o->e.resize(0); } } -} - -inline flatbuffers::Offset FooTable::Pack(flatbuffers::FlatBufferBuilder &_fbb, const FooTableT* _o, const flatbuffers::rehasher_function_t *_rehasher) { - return CreateFooTable(_fbb, _o, _rehasher); -} - -inline flatbuffers::Offset CreateFooTable(flatbuffers::FlatBufferBuilder &_fbb, const FooTableT *_o, const flatbuffers::rehasher_function_t *_rehasher) { - (void)_rehasher; - (void)_o; - struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const FooTableT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va; - auto _a = _o->a; - auto _b = _o->b; - auto _c = _fbb.CreateString(_o->c); - auto _d = _o->d.size() ? _fbb.CreateVectorOfStructs(_o->d) : 0; - auto _e = _o->e.size() ? _fbb.CreateVectorOfStructs(_o->e) : 0; - return keyfield::sample::CreateFooTable( - _fbb, - _a, - _b, - _c, - _d, - _e); -} - -inline const flatbuffers::TypeTable *BazTypeTable() { - static const flatbuffers::TypeCode type_codes[] = { - { flatbuffers::ET_UCHAR, 1, -1 }, - { flatbuffers::ET_UCHAR, 0, -1 } - }; - static const int16_t array_sizes[] = { 4, }; - static const int64_t values[] = { 0, 4, 5 }; - static const char * const names[] = { - "a", - "b" - }; - static const flatbuffers::TypeTable tt = { - flatbuffers::ST_STRUCT, 2, type_codes, nullptr, array_sizes, values, names - }; - return &tt; -} - -inline const flatbuffers::TypeTable *BarTypeTable() { - static const flatbuffers::TypeCode type_codes[] = { - { flatbuffers::ET_FLOAT, 1, -1 }, - { flatbuffers::ET_UCHAR, 0, -1 } - }; - static const int16_t array_sizes[] = { 3, }; - static const int64_t values[] = { 0, 12, 16 }; - static const char * const names[] = { - "a", - "b" - }; - static const flatbuffers::TypeTable tt = { - flatbuffers::ST_STRUCT, 2, type_codes, nullptr, array_sizes, values, names - }; - return &tt; -} - -inline const flatbuffers::TypeTable *FooTableTypeTable() { - static const flatbuffers::TypeCode type_codes[] = { - { flatbuffers::ET_INT, 0, -1 }, - { flatbuffers::ET_INT, 0, -1 }, - { flatbuffers::ET_STRING, 0, -1 }, - { flatbuffers::ET_SEQUENCE, 1, 0 }, - { flatbuffers::ET_SEQUENCE, 1, 1 } - }; - static const flatbuffers::TypeFunction type_refs[] = { - keyfield::sample::BazTypeTable, - keyfield::sample::BarTypeTable - }; - static const char * const names[] = { - "a", - "b", - "c", - "d", - "e" - }; - static const flatbuffers::TypeTable tt = { - flatbuffers::ST_TABLE, 5, type_codes, type_refs, nullptr, nullptr, names - }; - return &tt; -} - inline const keyfield::sample::FooTable *GetFooTable(const void *buf) { return flatbuffers::GetRoot(buf); } @@ -431,14 +232,6 @@ inline const keyfield::sample::FooTable *GetSizePrefixedFooTable(const void *buf return flatbuffers::GetSizePrefixedRoot(buf); } -inline FooTable *GetMutableFooTable(void *buf) { - return flatbuffers::GetMutableRoot(buf); -} - -inline keyfield::sample::FooTable *GetMutableSizePrefixedFooTable(void *buf) { - return flatbuffers::GetMutableSizePrefixedRoot(buf); -} - inline bool VerifyFooTableBuffer( flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer(nullptr); @@ -461,18 +254,6 @@ inline void FinishSizePrefixedFooTableBuffer( fbb.FinishSizePrefixed(root); } -inline flatbuffers::unique_ptr UnPackFooTable( - const void *buf, - const flatbuffers::resolver_function_t *res = nullptr) { - return flatbuffers::unique_ptr(GetFooTable(buf)->UnPack(res)); -} - -inline flatbuffers::unique_ptr UnPackSizePrefixedFooTable( - const void *buf, - const flatbuffers::resolver_function_t *res = nullptr) { - return flatbuffers::unique_ptr(GetSizePrefixedFooTable(buf)->UnPack(res)); -} - } // namespace sample } // namespace keyfield From 6a03956753836f62efdb55bb054e2af0ed312bef Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Fri, 2 Dec 2022 06:56:46 +0000 Subject: [PATCH 05/23] update --- tests/key_field/key_field_sample_generated.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index a436afd861f..c6d6ad9cd44 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -101,7 +101,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { } int KeyCompareWithValue(const flatbuffers::Array *_a) const { for (auto i = 0; i < a()->size(); i++) { - const auto a_l = flatbuffers::(a_[i]); + const auto a_l = flatbuffers::EndianScalar(a_[i]); const auto a_r = _a->Get(i); if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); From 736d997566ed0494385596d1b651df1a97440c73 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Fri, 2 Dec 2022 08:03:36 +0000 Subject: [PATCH 06/23] use Array instead --- src/idl_gen_cpp.cpp | 3 ++- tests/key_field/key_field_sample_generated.h | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index a4706e663ad..54899cecb02 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2309,8 +2309,9 @@ class CppGenerator : public BaseGenerator { code_ += " int KeyCompareWithValue(const {{INPUT_TYPE}} *_{{FIELD_NAME}}" ") const { "; + code_ += " curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; code_ += " for (auto i = 0; i < {{FIELD_NAME}}()->size(); i++) {"; - code_ += " const auto {{FIELD_NAME}}_l = flatbuffers::EndianScalar({{FIELD_NAME}}_[i]);"; + code_ += " const auto {{FIELD_NAME}}_l = curr_{{FIELD_NAME}}->Get(i);"; code_ += " const auto {{FIELD_NAME}}_r = _{{FIELD_NAME}}->Get(i);"; code_ += " if({{FIELD_NAME}}_l != {{FIELD_NAME}}_r) "; code_ += diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index c6d6ad9cd44..ef9492f29be 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -48,8 +48,9 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { return KeyCompareWithValue(o->a()) < 0; } int KeyCompareWithValue(const flatbuffers::Array *_a) const { + curr_a = a(); for (auto i = 0; i < a()->size(); i++) { - const auto a_l = flatbuffers::EndianScalar(a_[i]); + const auto a_l = curr_a->Get(i); const auto a_r = _a->Get(i); if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); @@ -100,8 +101,9 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { return KeyCompareWithValue(o->a()) < 0; } int KeyCompareWithValue(const flatbuffers::Array *_a) const { + curr_a = a(); for (auto i = 0; i < a()->size(); i++) { - const auto a_l = flatbuffers::EndianScalar(a_[i]); + const auto a_l = curr_a->Get(i); const auto a_r = _a->Get(i); if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); From c2c86df85f80829d447a5e0f03abf820b68d829f Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Fri, 2 Dec 2022 08:04:04 +0000 Subject: [PATCH 07/23] clang format --- src/idl_gen_cpp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 54899cecb02..4aa4904b757 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2311,7 +2311,8 @@ class CppGenerator : public BaseGenerator { ") const { "; code_ += " curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; code_ += " for (auto i = 0; i < {{FIELD_NAME}}()->size(); i++) {"; - code_ += " const auto {{FIELD_NAME}}_l = curr_{{FIELD_NAME}}->Get(i);"; + code_ += + " const auto {{FIELD_NAME}}_l = curr_{{FIELD_NAME}}->Get(i);"; code_ += " const auto {{FIELD_NAME}}_r = _{{FIELD_NAME}}->Get(i);"; code_ += " if({{FIELD_NAME}}_l != {{FIELD_NAME}}_r) "; code_ += From b41084315acfad6030c239057619bdee660856e7 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Fri, 2 Dec 2022 08:14:44 +0000 Subject: [PATCH 08/23] address error --- tests/key_field/key_field_sample_generated.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index ef9492f29be..308616b2705 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -47,12 +47,12 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { bool KeyCompareLessThan(const Baz * const o) const { return KeyCompareWithValue(o->a()) < 0; } - int KeyCompareWithValue(const flatbuffers::Array *_a) const { - curr_a = a(); + int KeyCompareWithValue(const flatbuffers::Array *_a) const { + auto curr_a = a(); for (auto i = 0; i < a()->size(); i++) { const auto a_l = curr_a->Get(i); const auto a_r = _a->Get(i); - if(a_l != a_r) + if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); } return 0; @@ -100,12 +100,12 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { bool KeyCompareLessThan(const Bar * const o) const { return KeyCompareWithValue(o->a()) < 0; } - int KeyCompareWithValue(const flatbuffers::Array *_a) const { - curr_a = a(); + int KeyCompareWithValue(const flatbuffers::Array *_a) const { + auto curr_a = a(); for (auto i = 0; i < a()->size(); i++) { const auto a_l = curr_a->Get(i); const auto a_r = _a->Get(i); - if(a_l != a_r) + if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); } return 0; From 535d7a7cad1d3450212bff01a34762d38c6da855 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Fri, 2 Dec 2022 08:15:33 +0000 Subject: [PATCH 09/23] clang --- src/idl_gen_cpp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 4aa4904b757..f841c73fefb 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2309,7 +2309,7 @@ class CppGenerator : public BaseGenerator { code_ += " int KeyCompareWithValue(const {{INPUT_TYPE}} *_{{FIELD_NAME}}" ") const { "; - code_ += " curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; + code_ += " auto curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; code_ += " for (auto i = 0; i < {{FIELD_NAME}}()->size(); i++) {"; code_ += " const auto {{FIELD_NAME}}_l = curr_{{FIELD_NAME}}->Get(i);"; From 8095517129c0fa33093027d3687f8ca8cbf5f227 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Fri, 2 Dec 2022 08:46:46 +0000 Subject: [PATCH 10/23] update --- src/idl_gen_cpp.cpp | 2 +- tests/key_field/key_field_sample_generated.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index f841c73fefb..f9f6d64c53b 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2310,7 +2310,7 @@ class CppGenerator : public BaseGenerator { " int KeyCompareWithValue(const {{INPUT_TYPE}} *_{{FIELD_NAME}}" ") const { "; code_ += " auto curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; - code_ += " for (auto i = 0; i < {{FIELD_NAME}}()->size(); i++) {"; + code_ += " for (auto i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; code_ += " const auto {{FIELD_NAME}}_l = curr_{{FIELD_NAME}}->Get(i);"; code_ += " const auto {{FIELD_NAME}}_r = _{{FIELD_NAME}}->Get(i);"; diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index 308616b2705..5f109302e2f 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -49,7 +49,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { } int KeyCompareWithValue(const flatbuffers::Array *_a) const { auto curr_a = a(); - for (auto i = 0; i < a()->size(); i++) { + for (auto i = 0; i < curr_a->size(); i++) { const auto a_l = curr_a->Get(i); const auto a_r = _a->Get(i); if(a_l != a_r) @@ -102,7 +102,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { } int KeyCompareWithValue(const flatbuffers::Array *_a) const { auto curr_a = a(); - for (auto i = 0; i < a()->size(); i++) { + for (auto i = 0; i < curr_a->size(); i++) { const auto a_l = curr_a->Get(i); const auto a_r = _a->Get(i); if(a_l != a_r) From 8d17ef3cad67b23ae766a2cd760240acc2f439ae Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Fri, 2 Dec 2022 19:50:30 +0000 Subject: [PATCH 11/23] manually generate --- tests/key_field/key_field_sample_generated.h | 219 +++++++++++++++++++ 1 file changed, 219 insertions(+) diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index 5f109302e2f..225ab9bce23 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -22,6 +22,20 @@ struct Bar; struct FooTable; struct FooTableBuilder; +struct FooTableT; + +bool operator==(const Baz &lhs, const Baz &rhs); +bool operator!=(const Baz &lhs, const Baz &rhs); +bool operator==(const Bar &lhs, const Bar &rhs); +bool operator!=(const Bar &lhs, const Bar &rhs); +bool operator==(const FooTableT &lhs, const FooTableT &rhs); +bool operator!=(const FooTableT &lhs, const FooTableT &rhs); + +inline const flatbuffers::TypeTable *BazTypeTable(); + +inline const flatbuffers::TypeTable *BarTypeTable(); + +inline const flatbuffers::TypeTable *FooTableTypeTable(); FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { private: @@ -29,6 +43,9 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { uint8_t b_; public: + static const flatbuffers::TypeTable *MiniReflectTypeTable() { + return BazTypeTable(); + } Baz() : a_(), b_(0) { @@ -44,6 +61,9 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { const flatbuffers::Array *a() const { return &flatbuffers::CastToArray(a_); } + flatbuffers::Array *mutable_a() { + return &flatbuffers::CastToArray(a_); + } bool KeyCompareLessThan(const Baz * const o) const { return KeyCompareWithValue(o->a()) < 0; } @@ -60,9 +80,23 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { uint8_t b() const { return flatbuffers::EndianScalar(b_); } + void mutate_b(uint8_t _b) { + flatbuffers::WriteScalar(&b_, _b); + } }; FLATBUFFERS_STRUCT_END(Baz, 5); +inline bool operator==(const Baz &lhs, const Baz &rhs) { + return + (lhs.a() == rhs.a()) && + (lhs.b() == rhs.b()); +} + +inline bool operator!=(const Baz &lhs, const Baz &rhs) { + return !(lhs == rhs); +} + + FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { private: float a_[3]; @@ -70,6 +104,9 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { int8_t padding0__; int16_t padding1__; public: + static const flatbuffers::TypeTable *MiniReflectTypeTable() { + return BarTypeTable(); + } Bar() : a_(), b_(0), @@ -97,6 +134,9 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { const flatbuffers::Array *a() const { return &flatbuffers::CastToArray(a_); } + flatbuffers::Array *mutable_a() { + return &flatbuffers::CastToArray(a_); + } bool KeyCompareLessThan(const Bar * const o) const { return KeyCompareWithValue(o->a()) < 0; } @@ -113,11 +153,38 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { uint8_t b() const { return flatbuffers::EndianScalar(b_); } + void mutate_b(uint8_t _b) { + flatbuffers::WriteScalar(&b_, _b); + } }; FLATBUFFERS_STRUCT_END(Bar, 16); +inline bool operator==(const Bar &lhs, const Bar &rhs) { + return + (lhs.a() == rhs.a()) && + (lhs.b() == rhs.b()); +} + +inline bool operator!=(const Bar &lhs, const Bar &rhs) { + return !(lhs == rhs); +} + + +struct FooTableT : public flatbuffers::NativeTable { + typedef FooTable TableType; + int32_t a = 0; + int32_t b = 0; + std::string c{}; + std::vector d{}; + std::vector e{}; +}; + struct FooTable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef FooTableT NativeTableType; typedef FooTableBuilder Builder; + static const flatbuffers::TypeTable *MiniReflectTypeTable() { + return FooTableTypeTable(); + } enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_A = 4, VT_B = 6, @@ -128,12 +195,21 @@ struct FooTable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { int32_t a() const { return GetField(VT_A, 0); } + bool mutate_a(int32_t _a = 0) { + return SetField(VT_A, _a, 0); + } int32_t b() const { return GetField(VT_B, 0); } + bool mutate_b(int32_t _b = 0) { + return SetField(VT_B, _b, 0); + } const flatbuffers::String *c() const { return GetPointer(VT_C); } + flatbuffers::String *mutable_c() { + return GetPointer(VT_C); + } bool KeyCompareLessThan(const FooTable * const o) const { return *c() < *o->c(); } @@ -143,9 +219,15 @@ struct FooTable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { const flatbuffers::Vector *d() const { return GetPointer *>(VT_D); } + flatbuffers::Vector *mutable_d() { + return GetPointer *>(VT_D); + } const flatbuffers::Vector *e() const { return GetPointer *>(VT_E); } + flatbuffers::Vector *mutable_e() { + return GetPointer *>(VT_E); + } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, VT_A, 4) && @@ -158,6 +240,9 @@ struct FooTable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { verifier.VerifyVector(e()) && verifier.EndTable(); } + FooTableT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(FooTableT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const FooTableT* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); }; struct FooTableBuilder { @@ -226,6 +311,120 @@ inline flatbuffers::Offset CreateFooTableDirect( e__); } +flatbuffers::Offset CreateFooTable(flatbuffers::FlatBufferBuilder &_fbb, const FooTableT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + + +inline bool operator==(const FooTableT &lhs, const FooTableT &rhs) { + return + (lhs.a == rhs.a) && + (lhs.b == rhs.b) && + (lhs.c == rhs.c) && + (lhs.d == rhs.d) && + (lhs.e == rhs.e); +} + +inline bool operator!=(const FooTableT &lhs, const FooTableT &rhs) { + return !(lhs == rhs); +} + + +inline FooTableT *FooTable::UnPack(const flatbuffers::resolver_function_t *_resolver) const { + auto _o = std::unique_ptr(new FooTableT()); + UnPackTo(_o.get(), _resolver); + return _o.release(); +} + +inline void FooTable::UnPackTo(FooTableT *_o, const flatbuffers::resolver_function_t *_resolver) const { + (void)_o; + (void)_resolver; + { auto _e = a(); _o->a = _e; } + { auto _e = b(); _o->b = _e; } + { auto _e = c(); if (_e) _o->c = _e->str(); } + { auto _e = d(); if (_e) { _o->d.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->d[_i] = *_e->Get(_i); } } else { _o->d.resize(0); } } + { auto _e = e(); if (_e) { _o->e.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->e[_i] = *_e->Get(_i); } } else { _o->e.resize(0); } } +} + +inline flatbuffers::Offset FooTable::Pack(flatbuffers::FlatBufferBuilder &_fbb, const FooTableT* _o, const flatbuffers::rehasher_function_t *_rehasher) { + return CreateFooTable(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateFooTable(flatbuffers::FlatBufferBuilder &_fbb, const FooTableT *_o, const flatbuffers::rehasher_function_t *_rehasher) { + (void)_rehasher; + (void)_o; + struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const FooTableT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va; + auto _a = _o->a; + auto _b = _o->b; + auto _c = _fbb.CreateString(_o->c); + auto _d = _o->d.size() ? _fbb.CreateVectorOfStructs(_o->d) : 0; + auto _e = _o->e.size() ? _fbb.CreateVectorOfStructs(_o->e) : 0; + return keyfield::sample::CreateFooTable( + _fbb, + _a, + _b, + _c, + _d, + _e); +} + +inline const flatbuffers::TypeTable *BazTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { + { flatbuffers::ET_UCHAR, 1, -1 }, + { flatbuffers::ET_UCHAR, 0, -1 } + }; + static const int16_t array_sizes[] = { 4, }; + static const int64_t values[] = { 0, 4, 5 }; + static const char * const names[] = { + "a", + "b" + }; + static const flatbuffers::TypeTable tt = { + flatbuffers::ST_STRUCT, 2, type_codes, nullptr, array_sizes, values, names + }; + return &tt; +} + +inline const flatbuffers::TypeTable *BarTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { + { flatbuffers::ET_FLOAT, 1, -1 }, + { flatbuffers::ET_UCHAR, 0, -1 } + }; + static const int16_t array_sizes[] = { 3, }; + static const int64_t values[] = { 0, 12, 16 }; + static const char * const names[] = { + "a", + "b" + }; + static const flatbuffers::TypeTable tt = { + flatbuffers::ST_STRUCT, 2, type_codes, nullptr, array_sizes, values, names + }; + return &tt; +} + +inline const flatbuffers::TypeTable *FooTableTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { + { flatbuffers::ET_INT, 0, -1 }, + { flatbuffers::ET_INT, 0, -1 }, + { flatbuffers::ET_STRING, 0, -1 }, + { flatbuffers::ET_SEQUENCE, 1, 0 }, + { flatbuffers::ET_SEQUENCE, 1, 1 } + }; + static const flatbuffers::TypeFunction type_refs[] = { + keyfield::sample::BazTypeTable, + keyfield::sample::BarTypeTable + }; + static const char * const names[] = { + "a", + "b", + "c", + "d", + "e" + }; + static const flatbuffers::TypeTable tt = { + flatbuffers::ST_TABLE, 5, type_codes, type_refs, nullptr, nullptr, names + }; + return &tt; +} + inline const keyfield::sample::FooTable *GetFooTable(const void *buf) { return flatbuffers::GetRoot(buf); } @@ -234,6 +433,14 @@ inline const keyfield::sample::FooTable *GetSizePrefixedFooTable(const void *buf return flatbuffers::GetSizePrefixedRoot(buf); } +inline FooTable *GetMutableFooTable(void *buf) { + return flatbuffers::GetMutableRoot(buf); +} + +inline keyfield::sample::FooTable *GetMutableSizePrefixedFooTable(void *buf) { + return flatbuffers::GetMutableSizePrefixedRoot(buf); +} + inline bool VerifyFooTableBuffer( flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer(nullptr); @@ -256,6 +463,18 @@ inline void FinishSizePrefixedFooTableBuffer( fbb.FinishSizePrefixed(root); } +inline flatbuffers::unique_ptr UnPackFooTable( + const void *buf, + const flatbuffers::resolver_function_t *res = nullptr) { + return flatbuffers::unique_ptr(GetFooTable(buf)->UnPack(res)); +} + +inline flatbuffers::unique_ptr UnPackSizePrefixedFooTable( + const void *buf, + const flatbuffers::resolver_function_t *res = nullptr) { + return flatbuffers::unique_ptr(GetSizePrefixedFooTable(buf)->UnPack(res)); +} + } // namespace sample } // namespace keyfield From 931e76be0d0eec31fbb70462a6649446caea3f4e Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Fri, 2 Dec 2022 20:49:03 -0800 Subject: [PATCH 12/23] Move Nim to completed language --- readme.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 9949ba66f00..b7a67ca4b86 100644 --- a/readme.md +++ b/readme.md @@ -42,10 +42,7 @@ Code generation and runtime libraries for many popular languages. 1. Rust - [crates.io](https://crates.io/crates/flatbuffers) 1. Swift 1. TypeScript - [NPM](https://www.npmjs.com/package/flatbuffers) - -*and more in progress...* - -1. [Nim](https://github.com/google/flatbuffers/pull/7362) +1. Nim ## Contribution From a884533b15b6b51dc3ff26e970583cceeca388bf Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Fri, 2 Dec 2022 20:52:20 -0800 Subject: [PATCH 13/23] Add swift link --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index b7a67ca4b86..83fa84adb20 100644 --- a/readme.md +++ b/readme.md @@ -40,7 +40,7 @@ Code generation and runtime libraries for many popular languages. 1. PHP 1. Python - [PyPi](https://pypi.org/project/flatbuffers/) 1. Rust - [crates.io](https://crates.io/crates/flatbuffers) -1. Swift +1. Swift - [swiftpackageindex](https://swiftpackageindex.com/google/flatbuffers) 1. TypeScript - [NPM](https://www.npmjs.com/package/flatbuffers) 1. Nim From 772bd7818d38c62c7a905f01deba8c22aa0c87ff Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Sun, 4 Dec 2022 20:40:14 +0000 Subject: [PATCH 14/23] address comments --- src/idl_gen_cpp.cpp | 2 +- tests/key_field/key_field_sample_generated.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index f9f6d64c53b..2d24aa1ef0d 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2309,7 +2309,7 @@ class CppGenerator : public BaseGenerator { code_ += " int KeyCompareWithValue(const {{INPUT_TYPE}} *_{{FIELD_NAME}}" ") const { "; - code_ += " auto curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; + code_ += " const auto* curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; code_ += " for (auto i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; code_ += " const auto {{FIELD_NAME}}_l = curr_{{FIELD_NAME}}->Get(i);"; diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index 225ab9bce23..d65098f1a88 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -67,12 +67,12 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { bool KeyCompareLessThan(const Baz * const o) const { return KeyCompareWithValue(o->a()) < 0; } - int KeyCompareWithValue(const flatbuffers::Array *_a) const { - auto curr_a = a(); + int KeyCompareWithValue(const flatbuffers::Array *_a) const { + const auto* curr_a = a(); for (auto i = 0; i < curr_a->size(); i++) { const auto a_l = curr_a->Get(i); const auto a_r = _a->Get(i); - if(a_l != a_r) + if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); } return 0; @@ -140,12 +140,12 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { bool KeyCompareLessThan(const Bar * const o) const { return KeyCompareWithValue(o->a()) < 0; } - int KeyCompareWithValue(const flatbuffers::Array *_a) const { - auto curr_a = a(); + int KeyCompareWithValue(const flatbuffers::Array *_a) const { + const auto* curr_a = a(); for (auto i = 0; i < curr_a->size(); i++) { const auto a_l = curr_a->Get(i); const auto a_r = _a->Get(i); - if(a_l != a_r) + if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); } return 0; From 010f7293e2f3b34da2af70913fcd4e67580f88e5 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Sun, 4 Dec 2022 20:47:44 +0000 Subject: [PATCH 15/23] update unit test --- tests/key_field_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/key_field_test.cpp b/tests/key_field_test.cpp index 6814bb43b81..da762d20a5e 100644 --- a/tests/key_field_test.cpp +++ b/tests/key_field_test.cpp @@ -50,7 +50,7 @@ void FixedSizedScalarKeyInStructTest() { TEST_EQ(sorted_baz_vec->Get(3)->b(), 4); uint8_t test_array[4]; - auto key_array = &flatbuffers::CastToArray(test_array); + auto* key_array = &flatbuffers::CastToArray(test_array); key_array->CopyFromSpan(flatbuffers::make_span(test_array1)); @@ -69,7 +69,7 @@ void FixedSizedScalarKeyInStructTest() { TEST_EQ(sorted_bar_vec->Get(3)->b(), 4); float test_float_array[3]; - auto key_float_array = &flatbuffers::CastToArray(test_float_array); + auto* key_float_array = &flatbuffers::CastToArray(test_float_array); key_float_array->CopyFromSpan(flatbuffers::make_span(test_float_array1)); TEST_NOTNULL(sorted_bar_vec->LookupByKey(key_float_array)); TEST_EQ(sorted_bar_vec->LookupByKey(key_float_array)->b(), 3); From 6a1a150aa88d4bdc2ed9d20446e94bf119cab1b1 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Mon, 5 Dec 2022 22:25:27 +0000 Subject: [PATCH 16/23] address comment --- src/idl_gen_cpp.cpp | 15 +++++++-------- tests/key_field/key_field_sample_generated.h | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 2d24aa1ef0d..f79ebe3621e 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2309,16 +2309,15 @@ class CppGenerator : public BaseGenerator { code_ += " int KeyCompareWithValue(const {{INPUT_TYPE}} *_{{FIELD_NAME}}" ") const { "; - code_ += " const auto* curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; - code_ += " for (auto i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; + code_ += " const {{INPUT_TYPE}} *curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; + code_ += " for (size_t i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; code_ += - " const auto {{FIELD_NAME}}_l = curr_{{FIELD_NAME}}->Get(i);"; - code_ += " const auto {{FIELD_NAME}}_r = _{{FIELD_NAME}}->Get(i);"; - code_ += " if({{FIELD_NAME}}_l != {{FIELD_NAME}}_r) "; + " const auto lhs = curr_{{FIELD_NAME}}->Get(i);"; + code_ += " const auto rhs = _{{FIELD_NAME}}->Get(i);"; + code_ += " if(lhs != rhs) "; code_ += - " return static_cast({{FIELD_NAME}}_l > " - "{{FIELD_NAME}}_r)" - " - static_cast({{FIELD_NAME}}_l < {{FIELD_NAME}}_r);"; + " return static_cast(lhs > rhs)" + " - static_cast(lhs < rhs);"; code_ += " }"; code_ += " return 0;"; } diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index d65098f1a88..7b8cc16e9ab 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -69,7 +69,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { } int KeyCompareWithValue(const flatbuffers::Array *_a) const { const auto* curr_a = a(); - for (auto i = 0; i < curr_a->size(); i++) { + for (size_t i = 0; i < curr_a->size(); i++) { const auto a_l = curr_a->Get(i); const auto a_r = _a->Get(i); if(a_l != a_r) @@ -142,7 +142,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { } int KeyCompareWithValue(const flatbuffers::Array *_a) const { const auto* curr_a = a(); - for (auto i = 0; i < curr_a->size(); i++) { + for (size_t i = 0; i < curr_a->size(); i++) { const auto a_l = curr_a->Get(i); const auto a_r = _a->Get(i); if(a_l != a_r) From df7e19ac3b1abe0cdf1115f9fc8b89d2d41eaa16 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Mon, 5 Dec 2022 22:27:10 +0000 Subject: [PATCH 17/23] address comment --- src/idl_gen_cpp.cpp | 7 ++++--- tests/key_field/key_field_sample_generated.h | 16 ++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index f79ebe3621e..17656970611 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2309,10 +2309,11 @@ class CppGenerator : public BaseGenerator { code_ += " int KeyCompareWithValue(const {{INPUT_TYPE}} *_{{FIELD_NAME}}" ") const { "; - code_ += " const {{INPUT_TYPE}} *curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; - code_ += " for (size_t i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; code_ += - " const auto lhs = curr_{{FIELD_NAME}}->Get(i);"; + " const {{INPUT_TYPE}} *curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; + code_ += + " for (size_t i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; + code_ += " const auto lhs = curr_{{FIELD_NAME}}->Get(i);"; code_ += " const auto rhs = _{{FIELD_NAME}}->Get(i);"; code_ += " if(lhs != rhs) "; code_ += diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index 7b8cc16e9ab..225ab9bce23 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -67,12 +67,12 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { bool KeyCompareLessThan(const Baz * const o) const { return KeyCompareWithValue(o->a()) < 0; } - int KeyCompareWithValue(const flatbuffers::Array *_a) const { - const auto* curr_a = a(); - for (size_t i = 0; i < curr_a->size(); i++) { + int KeyCompareWithValue(const flatbuffers::Array *_a) const { + auto curr_a = a(); + for (auto i = 0; i < curr_a->size(); i++) { const auto a_l = curr_a->Get(i); const auto a_r = _a->Get(i); - if(a_l != a_r) + if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); } return 0; @@ -140,12 +140,12 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { bool KeyCompareLessThan(const Bar * const o) const { return KeyCompareWithValue(o->a()) < 0; } - int KeyCompareWithValue(const flatbuffers::Array *_a) const { - const auto* curr_a = a(); - for (size_t i = 0; i < curr_a->size(); i++) { + int KeyCompareWithValue(const flatbuffers::Array *_a) const { + auto curr_a = a(); + for (auto i = 0; i < curr_a->size(); i++) { const auto a_l = curr_a->Get(i); const auto a_r = _a->Get(i); - if(a_l != a_r) + if(a_l != a_r) return static_cast(a_l > a_r) - static_cast(a_l < a_r); } return 0; From 730c1fca951d3243cae0abe2a433eb2679857eb5 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Mon, 5 Dec 2022 22:32:48 +0000 Subject: [PATCH 18/23] regenerate file --- tests/key_field/key_field_sample_generated.h | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index 225ab9bce23..df952cb1172 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -68,12 +68,12 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { return KeyCompareWithValue(o->a()) < 0; } int KeyCompareWithValue(const flatbuffers::Array *_a) const { - auto curr_a = a(); - for (auto i = 0; i < curr_a->size(); i++) { - const auto a_l = curr_a->Get(i); - const auto a_r = _a->Get(i); - if(a_l != a_r) - return static_cast(a_l > a_r) - static_cast(a_l < a_r); + const flatbuffers::Array *curr_a = a(); + for (size_t i = 0; i < curr_a->size(); i++) { + const auto lhs = curr_a->Get(i); + const auto rhs = _a->Get(i); + if(lhs != rhs) + return static_cast(lhs > rhs) - static_cast(lhs < rhs); } return 0; } @@ -141,12 +141,12 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { return KeyCompareWithValue(o->a()) < 0; } int KeyCompareWithValue(const flatbuffers::Array *_a) const { - auto curr_a = a(); - for (auto i = 0; i < curr_a->size(); i++) { - const auto a_l = curr_a->Get(i); - const auto a_r = _a->Get(i); - if(a_l != a_r) - return static_cast(a_l > a_r) - static_cast(a_l < a_r); + const flatbuffers::Array *curr_a = a(); + for (size_t i = 0; i < curr_a->size(); i++) { + const auto lhs = curr_a->Get(i); + const auto rhs = _a->Get(i); + if(lhs != rhs) + return static_cast(lhs > rhs) - static_cast(lhs < rhs); } return 0; } From 6d3431e241777b5dd0dc98eb84dd99e1b2e2f583 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Mon, 5 Dec 2022 23:17:57 +0000 Subject: [PATCH 19/23] use auto instead of size_t --- src/idl_gen_cpp.cpp | 2 +- tests/key_field/key_field_sample_generated.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 17656970611..10e57c211ac 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2312,7 +2312,7 @@ class CppGenerator : public BaseGenerator { code_ += " const {{INPUT_TYPE}} *curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; code_ += - " for (size_t i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; + " for (auto i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; code_ += " const auto lhs = curr_{{FIELD_NAME}}->Get(i);"; code_ += " const auto rhs = _{{FIELD_NAME}}->Get(i);"; code_ += " if(lhs != rhs) "; diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index df952cb1172..db5d8f31396 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -67,12 +67,12 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { bool KeyCompareLessThan(const Baz * const o) const { return KeyCompareWithValue(o->a()) < 0; } - int KeyCompareWithValue(const flatbuffers::Array *_a) const { + int KeyCompareWithValue(const flatbuffers::Array *_a) const { const flatbuffers::Array *curr_a = a(); - for (size_t i = 0; i < curr_a->size(); i++) { + for (auto i = 0; i < curr_a->size(); i++) { const auto lhs = curr_a->Get(i); const auto rhs = _a->Get(i); - if(lhs != rhs) + if(lhs != rhs) return static_cast(lhs > rhs) - static_cast(lhs < rhs); } return 0; @@ -140,12 +140,12 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { bool KeyCompareLessThan(const Bar * const o) const { return KeyCompareWithValue(o->a()) < 0; } - int KeyCompareWithValue(const flatbuffers::Array *_a) const { + int KeyCompareWithValue(const flatbuffers::Array *_a) const { const flatbuffers::Array *curr_a = a(); - for (size_t i = 0; i < curr_a->size(); i++) { + for (auto i = 0; i < curr_a->size(); i++) { const auto lhs = curr_a->Get(i); const auto rhs = _a->Get(i); - if(lhs != rhs) + if(lhs != rhs) return static_cast(lhs > rhs) - static_cast(lhs < rhs); } return 0; From 3182e02bc7bab4d86bc25146e0127dafc44b2a9e Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Tue, 6 Dec 2022 00:49:40 +0000 Subject: [PATCH 20/23] use uint32_t instead --- src/idl_gen_cpp.cpp | 2 +- tests/key_field/key_field_sample_generated.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 10e57c211ac..9d60ab64365 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2312,7 +2312,7 @@ class CppGenerator : public BaseGenerator { code_ += " const {{INPUT_TYPE}} *curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; code_ += - " for (auto i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; + " for (uint32_t i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; code_ += " const auto lhs = curr_{{FIELD_NAME}}->Get(i);"; code_ += " const auto rhs = _{{FIELD_NAME}}->Get(i);"; code_ += " if(lhs != rhs) "; diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index db5d8f31396..022c1f97186 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -69,7 +69,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { } int KeyCompareWithValue(const flatbuffers::Array *_a) const { const flatbuffers::Array *curr_a = a(); - for (auto i = 0; i < curr_a->size(); i++) { + for (uint32_t i = 0; i < curr_a->size(); i++) { const auto lhs = curr_a->Get(i); const auto rhs = _a->Get(i); if(lhs != rhs) @@ -142,7 +142,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { } int KeyCompareWithValue(const flatbuffers::Array *_a) const { const flatbuffers::Array *curr_a = a(); - for (auto i = 0; i < curr_a->size(); i++) { + for (uint32_t i = 0; i < curr_a->size(); i++) { const auto lhs = curr_a->Get(i); const auto rhs = _a->Get(i); if(lhs != rhs) From 75f62fac07f7cf1d93ab308cefac4a53bc78a8a4 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Tue, 6 Dec 2022 02:19:48 +0000 Subject: [PATCH 21/23] update --- src/idl_gen_cpp.cpp | 2 +- tests/key_field/key_field_sample_generated.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 3ce6a52adf2..d053651f850 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2273,7 +2273,7 @@ class CppGenerator : public BaseGenerator { code_ += " const {{INPUT_TYPE}} *curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; code_ += - " for (uint32_t i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; + " for (flatbuffers::uoffset_t i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; code_ += " const auto lhs = curr_{{FIELD_NAME}}->Get(i);"; code_ += " const auto rhs = _{{FIELD_NAME}}->Get(i);"; code_ += " if(lhs != rhs) "; diff --git a/tests/key_field/key_field_sample_generated.h b/tests/key_field/key_field_sample_generated.h index 022c1f97186..bcbd2d22181 100644 --- a/tests/key_field/key_field_sample_generated.h +++ b/tests/key_field/key_field_sample_generated.h @@ -69,7 +69,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) Baz FLATBUFFERS_FINAL_CLASS { } int KeyCompareWithValue(const flatbuffers::Array *_a) const { const flatbuffers::Array *curr_a = a(); - for (uint32_t i = 0; i < curr_a->size(); i++) { + for (flatbuffers::uoffset_t i = 0; i < curr_a->size(); i++) { const auto lhs = curr_a->Get(i); const auto rhs = _a->Get(i); if(lhs != rhs) @@ -142,7 +142,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Bar FLATBUFFERS_FINAL_CLASS { } int KeyCompareWithValue(const flatbuffers::Array *_a) const { const flatbuffers::Array *curr_a = a(); - for (uint32_t i = 0; i < curr_a->size(); i++) { + for (flatbuffers::uoffset_t i = 0; i < curr_a->size(); i++) { const auto lhs = curr_a->Get(i); const auto rhs = _a->Get(i); if(lhs != rhs) From 20aa3fba7b9ba0d232bd2d366b7c66edc3b56e4d Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Tue, 6 Dec 2022 02:20:01 +0000 Subject: [PATCH 22/23] format --- src/idl_gen_cpp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index d053651f850..bfefff51df3 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2273,7 +2273,8 @@ class CppGenerator : public BaseGenerator { code_ += " const {{INPUT_TYPE}} *curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; code_ += - " for (flatbuffers::uoffset_t i = 0; i < curr_{{FIELD_NAME}}->size(); i++) {"; + " for (flatbuffers::uoffset_t i = 0; i < " + "curr_{{FIELD_NAME}}->size(); i++) {"; code_ += " const auto lhs = curr_{{FIELD_NAME}}->Get(i);"; code_ += " const auto rhs = _{{FIELD_NAME}}->Get(i);"; code_ += " if(lhs != rhs) "; From 9d41fa76e58838eb4a8330bf3eff6f21135dfd92 Mon Sep 17 00:00:00 2001 From: Wen Sun Date: Tue, 6 Dec 2022 04:43:33 +0000 Subject: [PATCH 23/23] delete extra whitespace --- src/idl_gen_cpp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index bfefff51df3..5b9e181eb12 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2269,7 +2269,7 @@ class CppGenerator : public BaseGenerator { code_.SetValue("INPUT_TYPE", input_type); code_ += " int KeyCompareWithValue(const {{INPUT_TYPE}} *_{{FIELD_NAME}}" - ") const { "; + ") const {"; code_ += " const {{INPUT_TYPE}} *curr_{{FIELD_NAME}} = {{FIELD_NAME}}();"; code_ += @@ -2277,7 +2277,7 @@ class CppGenerator : public BaseGenerator { "curr_{{FIELD_NAME}}->size(); i++) {"; code_ += " const auto lhs = curr_{{FIELD_NAME}}->Get(i);"; code_ += " const auto rhs = _{{FIELD_NAME}}->Get(i);"; - code_ += " if(lhs != rhs) "; + code_ += " if(lhs != rhs)"; code_ += " return static_cast(lhs > rhs)" " - static_cast(lhs < rhs);";