templates and string literals and UNICODE

后端 未结 7 627
挽巷
挽巷 2020-12-18 09:50

NEW: Thank you everyone who helped me with this! The answer is marked below, and I\'ve expanded on the answer with a functioning version in my question, below (q.v.):

相关标签:
7条回答
  • 2020-12-18 10:35

    OK, so, if you really want to template this, I think the best thing I've been able to come up with is a templated class that stores your literals, based on this discussion. Something like this:

    template <typename T> class Literal;
    template <> class Literal<char>
    {
    public:
        static const char Quote = '"';
    };
    template <> class Literal<wchar_t>
    {
    public:
        static const wchar_t Quote = L'"';
    };
    

    Then, you'd use Literal<CHAR_T>::Quote in your non-specialized but templated functions. Kinda messy, I guess, but it has the benefit of leaving your function logic unduplicated and gives you templated string literals.

    0 讨论(0)
提交回复
热议问题