aboutsummaryrefslogtreecommitdiff
path: root/src/idl_gen_cpp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/idl_gen_cpp.cpp')
-rw-r--r--src/idl_gen_cpp.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp
index 12e43375..f74abbf8 100644
--- a/src/idl_gen_cpp.cpp
+++ b/src/idl_gen_cpp.cpp
@@ -1837,6 +1837,9 @@ class CppGenerator : public BaseGenerator {
code_ += " typedef {{NATIVE_NAME}} NativeTableType;";
}
code_ += " typedef {{STRUCT_NAME}}Builder Builder;";
+ if (opts_.g_cpp_std >= cpp::CPP_STD_17) {
+ code_ += " struct Traits;";
+ }
if (opts_.mini_reflect != IDLOptions::kNone) {
code_ +=
" static const flatbuffers::TypeTable *MiniReflectTypeTable() {";
@@ -2198,6 +2201,16 @@ class CppGenerator : public BaseGenerator {
code_ += "}";
code_ += "";
+ // Definition for type traits for this table type. This allows querying var-
+ // ious compile-time traits of the table.
+ if (opts_.g_cpp_std >= cpp::CPP_STD_17) {
+ code_ += "struct {{STRUCT_NAME}}::Traits {";
+ code_ += " using type = {{STRUCT_NAME}};";
+ code_ += " static auto constexpr Create = Create{{STRUCT_NAME}};";
+ code_ += "};";
+ code_ += "";
+ }
+
// Generate a CreateXDirect function with vector types as parameters
if (has_string_or_vector_fields) {
code_ +=