C++ Feature: Mutable union getters (#8852)

* generate mutable union accessors

* add test

* Revert "add test"

This reverts commit 45e352b18f.

* update file

* formatter got in the way

* merge conflicts

* updated genned code

* manually fix code gen bc I can't figure out why this file won't code gen

---------

Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
This commit is contained in:
Justin Davis
2025-12-21 17:36:47 -05:00
committed by GitHub
parent b1e7868db6
commit 7cb0bcb212
11 changed files with 375 additions and 8 deletions

View File

@@ -117,6 +117,10 @@ struct TableInFirstNS FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
const NamespaceA::NamespaceB::TableInNestedNS *foo_union_as_TableInNestedNS() const {
return foo_union_type() == NamespaceA::NamespaceB::UnionInNestedNS_TableInNestedNS ? static_cast<const NamespaceA::NamespaceB::TableInNestedNS *>(foo_union()) : nullptr;
}
template<typename T> T *mutable_foo_union_as();
NamespaceA::NamespaceB::TableInNestedNS *mutable_foo_union_as_TableInNestedNS() {
return foo_union_type() == NamespaceA::NamespaceB::UnionInNestedNS_TableInNestedNS ? static_cast<NamespaceA::NamespaceB::TableInNestedNS *>(mutable_foo_union()) : nullptr;
}
void *mutable_foo_union() {
return GetPointer<void *>(VT_FOO_UNION);
}
@@ -147,6 +151,10 @@ template<> inline const NamespaceA::NamespaceB::TableInNestedNS *TableInFirstNS:
return foo_union_as_TableInNestedNS();
}
template<> inline NamespaceA::NamespaceB::TableInNestedNS *TableInFirstNS::mutable_foo_union_as<NamespaceA::NamespaceB::TableInNestedNS>() {
return mutable_foo_union_as_TableInNestedNS();
}
struct TableInFirstNSBuilder {
typedef TableInFirstNS Table;
::flatbuffers::FlatBufferBuilder &fbb_;