C++14 Variable Templates: what is their purpose? Any usage example?

前端 未结 6 1739
死守一世寂寞
死守一世寂寞 2020-11-29 00:52

C++14 will allow the creation of variables that are templated. The usual example is a variable \'pi\' that can be read to get the value of the mathematical constant π for va

6条回答
  •  暖寄归人
    2020-11-29 01:22

    I have a use case here.

    template constexpr CT MARK = '%';
    template<> constexpr wchar_t MARK = L'%';
    

    which are used in a string processing template.`

    template  
    void ProcessString(const std::basic_string& str)
    {
        auto&& markpos = str.find(MARK);
        ...
    }
    

提交回复
热议问题