Boost logo

Boost Users :

From: Richard Damon (Richard_at_[hidden])
Date: 2019-10-30 11:50:09


On 10/30/19 1:03 AM, Zach Laine via Boost-users wrote:
>
> Yes, you got me.  I was speaking loosely, and referred to a template
> as if it were a type.  What I should have added was that a template's
> single responsibility should be to stamp out types that all model the
> same concept.  A policy-based template has a hard time doing that.  A
> policy-based template that stamps out strings with different
> invariants does not do that at all.
>
But all the various templates may well express a base concept even if
some of the invariants change between different template parameters. The
example of Unicode normalization, or memory allocator seem like perfect
examples of this. If an operation needs a particular normalization rule,
it specializes its parameter on that one case, otherwise it leaves it as
a template parameter.

To me, the basic invariant of a string is that it is a sequence of code
units that describe a textual object. Often the details of that encoding
are unimportant, it might be ASCII, it might be in some old code page,
it might be in UTF-8, it might be in UCS-4, and for the various Unicode
variations, there are different normalization rules to handle that a
given 'character' (aka Glyph) might be expressed in different ways, but
the routine largely doesn't care. When it does care, it can force the
string into that variant (or refuse some other variants), but the
purpose of templates is to condense duplicate code into a single piece
of code that only needs to be written once.

-- 
Richard Damon

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net