Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Ok. And what reason is that?


what 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 ?


...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?


cppreference 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.


Not 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...


string is a typedef of the template basic_string so you don't have to type as much I assume.


It would be nice if this worked:

    template <class T = char> class string { ... };

    string s = "a";


It 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;
    }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: