templates and string literals and UNICODE

后端 未结 7 635
挽巷
挽巷 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  class Literal;
    template <> class Literal
    {
    public:
        static const char Quote = '"';
    };
    template <> class Literal
    {
    public:
        static const wchar_t Quote = L'"';
    };
    

    Then, you'd use Literal::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.

提交回复
热议问题