5 ms·
Why 'basic_fixed_string'? Is it really so basic that it has to be mentioned in the name? Is it just in case there might be a 'fixed_string' that isn't quite as
by gridlockd 7y ago
Why 'basic_fixed_string'? Is it really so basic that it has to be mentioned in the name? Is it just in case there might be a 'fixed_string' that isn't quite as basic, in the future?
- jcelerier 7y agofor the same reason that std::string is std::basic_string<char>
- harry8 7y agoOk. And what reason is that?
- rightbyte 7y agostring is a typedef of the template basic_string so you don't have to type as much I assume.
- axilmar 7y agoIt would be nice if this worked: template <class T = char> class string { ... }; string s = "a";
- rightbyte 7y agoIt does with newer compilers. Was some bugs with gcc and clang earlier. Try: #include <cstdio> template <class T = char> class string { public: string(const T *const c) : c_ptr(c){} const T *const c_ptr; }; int main() { string s = "qwe"; printf("%s", s.c_ptr); return 0; }
- jcelerier 7y agowhat would you do instead ? surely you would not have std::string be a template directly and type std::string<char> / std::string<wchar_t> instead of std::string / std::wstring every time you want a string ?
- harry8 7y agoNot seeing a reason in this response for basic_${foo}, implying the existence of a ${not_so_basic}_string as was the original question. Sure typedef a template instantiation to get around language syntax awkwardness, that's fine. Why basic_string? why basic_fixed_string? Or is this just a curveball and it would have been better as typedef _string<char> string etc Or maybe not, I don't know what they had in mind, which is why I'm asking...
- gridlockd 7y ago...but unlike std::basic_string<T>, there is not template parameter for std::basic_fixed_string and there is no typedef of it as std::fixed_string. I suppose it opens up the possibility of adding std::basic_fixed_string<T> later and then have std::basic_fixed_string just be a specialization?
- gpderetta 7y agocppreference doesn't have it yet, but as far as I can tell from P0259R0, basic_fixed_string is a template, both parameterized on the char type and the size N, and I can't see how it could be otherwise. And no, if it weren't a template, it would not be possible to make it a template in the future as it would be a breaking change.