make Glib::ustring conversion to/from std::string explicit
This is follow-up on #35 (closed).
It is very easy to unconsciously create Glib::ustring
copies of std::string
instances, or vice versa. I consider this a flaw in the current API. Even comparing the two creates a copy:
Glib::ustring u;
Glib::string s;
if (u == s) { // <-- creates a Glib::ustring copy of s
}
This could be avoided by making the constructor and conversion operator explicit.
explicit inline ustring(const std::string& src);
explicit inline operator std::string() const;
This would be a change in the API, but not ABI breaking.
In case this behavior is not desired in general, I would make it optional with a preprocessor macro (e.g. -DGLIB_USTRING_EXPLICIT_STD_STRING_CONVERSION
), so that a developer has the choice to develop under more strict conditions and catch these undesired copies.
Edited by Thomas Holder