Tech Off Post

Single Post Permalink

View Thread: New C++ runtime library
  • User profile image

    @Sven Groot: I've wrtten my own string class which stores strings as reference couted unicode strings. It has constructors to handle a few different string types, and as you know with c++ this allows you to construct an object with a simple assignment.

    Regarding WriteLine(), it is type safe, but I had to resort to writing many templated overloads

    WriteLine(const String& s);
    template <typename A0>
    WriteLine(const String& s, const A0& a0) {}
    template <typename A0, typename A1>
    WriteLine(const String& s, const A0& a0, const A1& a1) {}

    Etc ... I also did the same thing with my Format() function. There is a single object hierarchy structure to my classes with the root being class ValueType. ValueType provides a ToFormat(const String&) method which allows customization of how classes can be formatted.

    When you say Format("Hello {0:base64}", memoryBuffer), the Format() function parses out "base64" from the 0th argument and passes that to a0.ToFormat(format) ... where format holds the value "base64".

    In this way any class can provide it's own formatting by simply override ToFormat(). For the default types like int, bool, double, etc I provide default formatters, eg: Format("{0:$#.##|-20}", dollarsAmount). Might return: "                 $150.00"