Use type traits for specialization (#7475)

This commit is contained in:
Derek Bailey
2022-08-24 12:16:44 -07:00
committed by GitHub
parent b7eb441470
commit 799cc8f7b9

View File

@@ -39,10 +39,11 @@ struct ImportDefinition {
enum AnnotationType { kParam = 0, kType = 1, kReturns = 2 };
template<typename T> bool SupportsObjectAPI() { return false; }
template<typename T>
struct SupportsObjectAPI : std::false_type {};
// Structs can have Object API support.
template<> bool SupportsObjectAPI<StructDef>() { return true; }
template<>
struct SupportsObjectAPI<StructDef> : std::true_type {};
} // namespace
@@ -756,7 +757,7 @@ class TsGenerator : public BaseGenerator {
flat_file_import_declarations_[file][import_name] = name;
if (parser_.opts.generate_object_based_api &&
SupportsObjectAPI<DefinitionT>()) {
SupportsObjectAPI<DefinitionT>::value) {
flat_file_import_declarations_[file][import_name + "T"] = object_name;
}
}