Skip to content

Commit

Permalink
Use type traits for specialization (google#7475)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaileychess authored and Jochen Parmentier committed Oct 29, 2024
1 parent 79cd508 commit b2b9727
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/idl_gen_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit b2b9727

Please sign in to comment.