From 5a4feee627e92796b3bc7353730cbfcab287fddb Mon Sep 17 00:00:00 2001 From: Lucian Grijincu Date: Wed, 16 Sep 2015 11:32:54 -0700 Subject: [PATCH] folly: ProgramOptions: avoid static init fiasco by using meyer's singleton Reviewed By: @elsteveogrande Differential Revision: D2446056 --- folly/experimental/ProgramOptions.cpp | 43 +++++++++++++-------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/folly/experimental/ProgramOptions.cpp b/folly/experimental/ProgramOptions.cpp index 8146722e..8cf27137 100644 --- a/folly/experimental/ProgramOptions.cpp +++ b/folly/experimental/ProgramOptions.cpp @@ -166,29 +166,11 @@ class NegativeBoolGFlagValueSemantic : public BoolGFlagValueSemantic { } }; -static const std::unordered_set gSkipFlags { - "flagfile", - "fromenv", - "tryfromenv", - "undefok", - "help", - "helpfull", - "helpshort", - "helpon", - "helpmatch", - "helppackage", - "helpxml", - "version", - "tab_completion_columns", - "tab_completion_word", -}; - -static const std::unordered_map gFlagOverrides { - // Allow -v in addition to --v - {"v", "v,v"}, -}; - const std::string& getName(const std::string& name) { + static const std::unordered_map gFlagOverrides{ + // Allow -v in addition to --v + {"v", "v,v"}, + }; auto pos = gFlagOverrides.find(name); return pos != gFlagOverrides.end() ? pos->second : name; } @@ -261,6 +243,23 @@ const std::unordered_map gFlagAdders = { } // namespace po::options_description getGFlags(ProgramOptionsStyle style) { + static const std::unordered_set gSkipFlags{ + "flagfile", + "fromenv", + "tryfromenv", + "undefok", + "help", + "helpfull", + "helpshort", + "helpon", + "helpmatch", + "helppackage", + "helpxml", + "version", + "tab_completion_columns", + "tab_completion_word", + }; + po::options_description desc("GFlags"); std::vector allFlags; -- 2.34.1