My personal approach to such things is to use property maps: I present a system of algorithms that can [optionally] take a property map (or actually sometimes several property maps) for each range. The idea is that *it gives a key (for example, T& , which it currently does), which is then used with a property map, which converts the key into an actually accessible value. A transformation can, for example, be an identity giving the current behavior of the algorithms and a good default value that will be used when there is no property map. The example above looks something like this:
auto const cursor = c.begin(); std::printf("%c\n", c.map_source()(*cursor)); std::printf("%c\n", c.map_upper()(*cursor)); c.map_source()(*cursor, 'x'); std::copy(c.map_source(), c, std::ostreambuf_iterator<char>(std::cout)); std::copy(c.map_upper(), c, std::ostreambuf_iterator<char>(std::cout)); std::copy([](unsigned char c)->char{ return std::toupper(c); }, c, std::ostreambuf_iterator<char>(std::cout));
The code assumes that property maps giving the source and capital characters are obtained using c.map_source() and c.map_upper() , respectively. The last option using std::copy() uses the lambda function as a property map.
Unfortunately, I still have not found time to write a joint proposal on the application of various improvements to the STL algorithms .... and I do not have an implementation that combines all this (I have a somewhat clumsy implementation that is about 10 years old and not use the various C ++ 11 features that make it a lot easier, and this implementation only focuses on property maps and does not use the interface that I currently see).
source share