On Wed, Oct 30, 2019 at 6:55 AM Richard Damon via Boost-users < boost-users@lists.boost.org> wrote:
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.
You're mixing kinds of abstractions here. There is the genericity you find
in a function that takes a generic parameter, and that's the kind of use
based on concept you're talking about here. About that you're 100% correct:
template