Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>char_traits</code> is indeed a hopelessly awful wastebin of random traits. Should every string pre-specify the largest supported file size, case-sensitivity, and (ugh) state type of the encoding mechanism itself? NO.</p> <p>However, what you ask is impossible even with well-designed traits. <code>string</code> and <code>wstring</code> are meaningfully different because the size of the internal character type differs. To run any kind of algorithm, you will need to query the object for <code>char_t</code>. That requires RTTI or virtual functions because <code>basic_string</code> doesn't (and shouldn't) maintain that info at runtime.</p> <blockquote> <p>One -possible- solution is to construct each library class as a template that manages the value_type, traits and allocators specified by the user. But that's overkill and makes abstract base classes (interfaces) impossible.</p> </blockquote> <p>This is the only complete solution. Templates actually <em>do</em> play well with abstract base classes: a number of templates can derive from a non-template abstract base, or the base can also be templated. However, it is difficult if not untenable because of the sensitivity and tedium of writing perfectly generic code.</p> <blockquote> <p>Another solution is to just specify one type (e.g. u32string) as default, every user must pass data using this type. But now think about a project which uses 3 libraries, and the first lib uses u32string, the second lib u16string and the thirth lib wstring -> HELL.</p> </blockquote> <p>This is why I'm scared by C++11's "improved" Unicode support. It simplifies direct interaction with file data and discourages abstraction to a <em>common</em> <code>wchar_t</code> internal format. It would have been better to require specific codecvts for UTF-16 and UTF-32 and specify that <code>wchar_t</code> must be at least 21 bits. Whereas before there were only "dumb" <code>char</code> and "smart" <code>wchar_t</code> libraries among clean C++ interfaces, we may have to contend with additional widths — and <code>char16_t</code> is just an instant red flag.</p> <p>But, that's down the road.</p> <p>If you really end up using a number of incompatible libraries, and the problem is shuttling data between functions requiring different formats, then write a <a href="http://drdobbs.com/cpp/184403758" rel="nofollow">ScopeGuard-style</a> utility to convert from and back to your chosen common format, such as <code>wstring</code>. This utility can be a template with an explicit specialization for each incompatible format you need, or a non-templated set of classes.</p>
    singulars
    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.
    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