3535#include < vector>
3636
3737// Regular expression for token delimiters (whitespace and commas)
38- static const std::regex program_options_regex{" [, \\ f\\ n\\ r\\ t\\ v]+" ,
39- std::regex_constants::optimize};
40-
41- static const std::regex vector_delim{" ," , std::regex_constants::optimize};
38+ #define PROGRAM_OPTIONS_REGEX " [, \\ f\\ n\\ r\\ t\\ v]+"
39+ #define VECTOR_DELIM " ,"
4240
4341// variables_map is a set of seen options
4442using variables_map = std::set<std::string>;
@@ -264,6 +262,9 @@ class options_description
264262 // Parse an option at the current (argc, argv) position
265263 void parse_option (int & argc, char **& argv, variables_map& vm, bool ignoreUnknown = false ) const
266264 {
265+ static const std::regex program_options_regex{PROGRAM_OPTIONS_REGEX,
266+ std::regex_constants::optimize};
267+
267268 // Iterate across all options
268269 for (const auto & opt : m_optlist)
269270 {
@@ -312,6 +313,9 @@ class options_description
312313 // Formatted output of command-line arguments description
313314 friend std::ostream& operator <<(std::ostream& os, const options_description& d)
314315 {
316+ static const std::regex program_options_regex{PROGRAM_OPTIONS_REGEX,
317+ std::regex_constants::optimize};
318+
315319 // Iterate across all options
316320 for (const auto & opt : d.m_optlist )
317321 {
@@ -404,6 +408,8 @@ inline void notify(const variables_map&) {}
404408
405409void parse_arg_ints (std::string const & inStr, std::vector<size_t >& outVector)
406410{
411+ static const std::regex vector_delim{VECTOR_DELIM, std::regex_constants::optimize};
412+
407413 // std::cout << inStr << std::endl;
408414 for (std::sregex_token_iterator tok{inStr.begin (), inStr.end (), vector_delim, -1 };
409415 tok != std::sregex_token_iterator ();
@@ -415,6 +421,8 @@ void parse_arg_ints(std::string const& inStr, std::vector<size_t>& outVector)
415421
416422void parse_arg_strings (std::string const & inStr, std::vector<std::string>& outVector)
417423{
424+ static const std::regex vector_delim{VECTOR_DELIM, std::regex_constants::optimize};
425+
418426 // std::cout << inStr << std::endl;
419427 for (std::sregex_token_iterator tok{inStr.begin (), inStr.end (), vector_delim, -1 };
420428 tok != std::sregex_token_iterator ();
0 commit comments