From 435a12ac07f53f0356d2894b704b1428fbf87528 Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Sat, 13 Jan 2024 18:56:40 +1000 Subject: [PATCH] Ordered vector of group names to preserve order of groups --- include/cxxopts.hpp | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index cbbef808..481826ce 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -2033,6 +2033,7 @@ class Options std::unordered_set m_positional_set{}; //mapping from groups to help options + std::vector m_group{}; std::map m_help{}; }; @@ -2671,6 +2672,12 @@ Options::add_option } //add the help details + + if (m_help.find(group) == m_help.end()) + { + m_group.push_back(group); + } + auto& options = m_help[group]; options.options.emplace_back(HelpOptionDetails{s, l, stringDesc, @@ -2802,19 +2809,7 @@ inline void Options::generate_all_groups_help(String& result) const { - std::vector all_groups; - - std::transform( - m_help.begin(), - m_help.end(), - std::back_inserter(all_groups), - [] (const std::map::value_type& group) - { - return group.first; - } - ); - - generate_group_help(result, all_groups); + generate_group_help(result, m_group); } inline @@ -2854,19 +2849,7 @@ inline std::vector Options::groups() const { - std::vector g; - - std::transform( - m_help.begin(), - m_help.end(), - std::back_inserter(g), - [] (const std::map::value_type& pair) - { - return pair.first; - } - ); - - return g; + return m_group; } inline