From bf17df346e368918b2382ae3f451dc47f4c12f77 Mon Sep 17 00:00:00 2001 From: Stefan F <32997632+stefan301@users.noreply.github.com> Date: Tue, 5 Apr 2022 00:20:55 +0200 Subject: [PATCH] [C++] generate sorted #include directives (#7213) * [C++] generate sorted #include directives * using stable_sort instead of sort. --- src/idl_gen_cpp.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index cf6522fac..459dfedd2 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -229,10 +229,17 @@ class CppGenerator : public BaseGenerator { num_includes++; } } + + std::vector include_files; for (auto it = parser_.included_files_.begin(); it != parser_.included_files_.end(); ++it) { if (it->second.empty()) continue; - auto noext = flatbuffers::StripExtension(it->second); + include_files.push_back(it->second); + } + std::stable_sort(include_files.begin(), include_files.end()); + + for (auto it = include_files.begin(); it != include_files.end(); ++it) { + auto noext = flatbuffers::StripExtension(*it); auto basename = flatbuffers::StripPath(noext); auto includeName = GeneratedFileName(opts_.include_prefix,