Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write a generic template for all basic_string instances
    text
    copied!<p>I am trying to write a template like this.</p> <pre><code>template &lt;char c,typename Options, basic_string&lt;class,class,class&gt; Options::* member&gt; struct option_string; </code></pre> <p>However I keep getting a compilation error. I would like to know how to write a template that takes three options: a <code>char</code>, any class and a pointer to a member of that class which must be a <code>basic_string</code> specialization. I want to avoid writing a template for each specialization of <code>basic_string</code>.</p> <p>My goal is to created a generic command line option library. The following is how I would like to use it.</p> <pre><code>class Options : public Command_Line_Options_Parser&lt;Options&gt; { public: int integer = 0; float real_number = 0.0; bool boolean = false; bool make_true = false; bool make_false = true; std::string string; typedef Options O; typedef Command_Line_Options&lt; option_int&lt;'i',&amp;O::integer&gt;, option_float&lt;'f',&amp;O::real_number&gt;, option_bool&lt;'b',&amp;O::boolean&gt;, option_true&lt;'t',&amp;O::make_true&gt;, option_false&lt;'t',&amp;O::make_true&gt;, option_string&lt;'s',&amp;O::string&gt; &gt; option_list; }; int main(int argc,char**argv ) { Options options; options.parse(argc,argv); std::cout &lt;&lt; "integer : " &lt;&lt; options.integer &lt;&lt;endl; std::cout &lt;&lt; "real_number : " &lt;&lt; options.real_number &lt;&lt;endl; std::cout &lt;&lt; "boolean : " &lt;&lt; options.boolean &lt;&lt;endl; std::cout &lt;&lt; "make_true : " &lt;&lt; options.make_true &lt;&lt;endl; std::cout &lt;&lt; "make_false : " &lt;&lt; options.make_false &lt;&lt;endl; std::cout &lt;&lt; "string : " &lt;&lt; options.string &lt;&lt;endl; }; </code></pre> <p>I would prefer for <code>option_string</code> to accept all specializations of <code>basic_string</code> instead of just <code>std::string</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload