Boost C++ Libraries: Ticket #4142: Option names should be constructible from strings https://svn.boost.org/trac10/ticket/4142 <p> The constructor and set_name methods of option_description take only const char pointers and not strings. (Likewise for the option_description_easy_init operator().) </p> <p> Currently code such as the below fails to compile </p> <pre class="wiki">std::string help="help"; po::options_description desc("Allowed options"); desc.add_options() (HELP, "produce help message"); </pre><p> We use strings for easy reuse them when checking the variable map of parsed options. </p> <p> This came up on the dev list last month, and Vladimir said he'd look into why overloads for strings didn't already exist.(<a class="ext-link" href="http://lists.boost.org/Archives/boost/2010/03/162646.php"><span class="icon">​</span>http://lists.boost.org/Archives/boost/2010/03/162646.php</a>) I assume you haven't had time, so here's a more persistent reminder. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4142 Trac 1.4.3 anonymous Mon, 26 Apr 2010 06:26:49 GMT <link>https://svn.boost.org/trac10/ticket/4142#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4142#comment:1</guid> <description> <p> Here is one problem. Lets look at the following declaration: </p> <pre class="wiki">options_description_easy_init::operator()(const char* name, const value_semantic* s, const char* description); </pre><p> Note that you can't replace it with </p> <pre class="wiki">options_description_easy_init::operator()(const std::string&amp; name, const value_semantic* s, const std::string&amp; description); </pre><p> because the latter is not exception-safe due to unspecified order of arguments' evaluation. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Mon, 26 Apr 2010 12:53:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4142#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4142#comment:2</guid> <description> <p> I am not sure I follow what exception safety issues are there? It's only possible to leak 's' when ctor of std::string throws, which can happen only in 'out of memory' condition, and I'm not sure I care much about that use case -- especially for a library that parses program's command line. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 27 Apr 2010 11:09:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4142#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4142#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4142#comment:2" title="Comment 2">vladimir_prus</a>: </p> <blockquote class="citation"> <p> I am not sure I follow what exception safety issues are there? It's only possible to leak 's' when ctor of std::string throws, </p> </blockquote> <p> Yes, that's what I meant. </p> <blockquote class="citation"> <p> which can happen only in 'out of memory' condition, and I'm not sure I care much about that use case -- especially for a library that parses program's command line. </p> </blockquote> <p> It is hard to argue against such reasoning. Don't forget that B.PO parses not only command line now. </p> </description> <category>Ticket</category> </item> <item> <author>Olaf van der Spek <olafvdspek@…></author> <pubDate>Sat, 01 Oct 2011 13:05:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4142#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4142#comment:4</guid> <description> <p> Instead of std::string, you could use a template function and use data() and size() member functions of the passed in argument. Or, better yet, support a str_ref class (not yet available in Boost). </p> </description> <category>Ticket</category> </item> </channel> </rss>