3 ms·
I'm not so happy with C++ string either. Main complaint is that I like the use of C strings as "semi-predicates"- you can test for NULL to indicate a failure.
by jhallenworld 13y ago
I'm not so happy with C++ string either. Main complaint is that I like the use of C strings as "semi-predicates"- you can test for NULL to indicate a failure. I wrote my own String class at one point to provide this feature:
// These provide test if assigned/not assigned
inline operator void*() const
{
return (void *)s;
}
inline bool operator!() const
{
if(s) return 0;
else return 1;
}
- dllthomas 13y agoBetter not to pun, and use an actual optional where you want it...
- jhallenworld 13y agoEh, I like my C idioms. With C++ it's easy to make it safe so that accessing an unassigned string doesn't cause a crash (make NULL equivalent to empty strings except for tests). I have the same gripe with the way the STL is designed. Too tedious to test for empty first before reading an item.
- deleted 13y ago[deleted]