
Emil Dotchevski wrote:
You're presuming that it makes sense to put converting to- and from- string into a single interface. For what it's worth, consider that sprintf/sscanf are separate interfaces too, despite the many similarities and analogies between them.
Unlike addition and subtraction which are symmetrical, converting to- and from- string isn't. For example I searched our source code for to_string and from_string. We have 314 occurrences of to_string (in 112 source files), and only 33 calls to from_string (in 11 source files.) Only 2 files use both to_string and from_string.
I agree that the "from-string" conversion is used less often than "to-string". However, that doesn't seem to me as a reason to separate the interface. If we forget for a moment about strings, parsing and formatting, we have a value of type A and want to get the corresponding value of type B. Regardless of the types, we have a common process of value and type transformation here. As partial cases it may involve parsing, formatting, character transcoding, type promotion - you name it. There were good examples of such transformation kinds, such as string<->wstring conversion and transforms between containers and their elements. I assume there can be connection with other Boost libraries, like Boost.NumericConversion or Boost.Units. This library has potential to become a common framework for conversion facilities that are reimplemented here and there quite often. And I feel that a common and well recognizable interface is very important for such a framework. That is, I think it would be better to use a common name for conversions in either direction (well, the direction doesn't matter anyway, from perspective of such a framework).