Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem you are having is related to the fact that <code>operator &lt;&lt; (ostream&amp;, char*)</code> is not a member of ostream, and your temporary ostream instance cannot bind to a non-<code>const</code> reference. Instead, it picks the <code>void*</code> overload, which is a member of ostream, and thus doesn't have that restriction.</p> <p>The best (but not easiest or most elegant, by any stretch of imagination!) would be to use the Boost Preprocessor to generate a large number of function overloads, each templated on a large number of objects (includes have been omitted and assuming <code>using namespace std;</code>):</p> <pre><code>#define MAKE_OUTPUT(z, n, data) \ BOOST_PP_TUPLE_ELEM(2, 0, data) &lt;&lt; BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, data), n); #define MAKE_FORMAT(z, n, data) \ template &lt;BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_INC(n), typename T)&gt; \ inline string format(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, BOOST_PP_INC(n), T, p)) \ { \ ostringstream s; \ BOOST_PP_REPEAT_##z(z, n, MAKE_OUTPUT, (s, p)); \ return s.str(); \ } </code></pre> <p>It's not guaranteed to work exactly (wrote it without testing), but that's basically the idea. You then call <code>BOOST_PP_REPEAT(N, MAKE_FORMAT, ())</code> to create a series of functions taking up to N parameters that will format your string as you want to (replace N with the integer of choice. Higher values may negatively affect compile times). This should suffice until you get a compiler with variadic templates. You should read the boost preprocessor documentation, it has very powerful features for things like this. (you can subsequently <code>#undef</code> the macros, after calling the <code>BOOST_PP_REPEAT</code> invocation to generate the functions)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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