Note that there are some explanatory texts on larger screens.

plurals
  1. POSimplest way to mix sequences of types with iostreams?
    primarykey
    data
    text
    <p>I have a function <code>void write&lt;typename T&gt;(const T&amp;)</code> which is implemented in terms of writing the T object to an ostream, and a matching function <code>T read&lt;typename T&gt;()</code> that reads a T from an istream. I am basically using iostreams as a plain text serialisation format, which obviously works fine for most built-in types, although I'm not sure how to effectively handle std::strings just yet.</p> <p>I'd like to be able to write out a sequence of objects too, eg <code>void write&lt;typename T&gt;(const std::vector&lt;T&gt;&amp;)</code> or an iterator based equivalent (although in practice, it would always be used with a vector). However, while writing an overload that iterates over the elements and writes them out is easy enough to do, this doesn't add enough information to allow the matching read operation to know how each element is delimited, which is essentially the same problem that I have with a single std::string.</p> <p>Is there a single approach that can work for all basic types and std::string? Or perhaps I can get away with 2 overloads, one for numerical types, and one for strings? (Either using different delimiters or the string using a delimiter escaping mechanism, perhaps.)</p> <p>EDIT: <em>I appreciate the often sensible tendency when confronted with questions like this is to say, "you don't want to do that" and to suggest a better approach, but I would really like suggestions that relate directly to what I asked, rather than what you believe I should have asked instead. :)</em></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. 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