Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You won't get around having to specify the return type directly. And in that case, why bother with the <code>basic_string</code> class directly? Just take a <code>typename String</code> and be done:</p> <pre><code>template&lt;char C, class Options, class String, String Options::* Member&gt; struct option_string; </code></pre> <p>And if you still want to make sure that <code>String</code> is indeed a specialization of <code>basic_string</code>, well, take this little helper and <code>static_assert</code> it:</p> <pre><code>#include &lt;type_traits&gt; #include &lt;string&gt; template&lt;class T&gt; struct is_basic_string : std::false_type{}; template&lt;class Ch, class Tr, class Al&gt; struct is_basic_string&lt;std::basic_string&lt;Ch,Tr,Al&gt;&gt; : std::true_type{}; // in 'option_string' static_assert(is_basic_string&lt;String&gt;::value, "Data member must be a 'basic_string' specialization."); </code></pre> <hr> <p>Since there doesn't seem to be a need to pass the member pointer as a template argument, I suggest just passing it in the constructor:</p> <pre><code>template&lt;char C, class Option, class String&gt; struct option_string{ static_assert(is_basic_string&lt;String&gt;::value, "Data member must be a 'basic_string' specialization."); typedef String Option::*member_type; option_string(member_type m, ...) : member(m), ... { ... } private: member_type member; }; template&lt;char C, class Option, class String&gt; option_string&lt;C, Option, String&gt; make_option_string(String Option::*member, ...){ return {member, ...}; } // in code: auto os = make_option_string&lt;'H'&gt;(&amp;some_type::a_string_member); </code></pre>
 

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