jeudi 5 juillet 2018

is it possible in modern c++ to pass string literal as parameter to c++ template?

Is it possible in "modern C++" (C++17 or greater) to pass a string literal as a parameter to a C++ template? I realize you could do this with constructor argument, I just thought it would be more convenient to have it as a template argument, rather than buried deep in the cpp file. Was curious if maybe this was a new feature of modern C++. See Pseudo code below of what I'm trying to do:

Pseudo-code Example:

// Header File /////////////////////////
template<string_literal Name>
class ModuleBase {
public:
     ModuleBase(); {
     string name;
}

class xyz : ModuleBase<"xyz"> {
public:
    xyz();
}

// Cpp File //////////////////////////
template<string_literal Name>
ModuleBase::ModuleBase() {
         name = Name;
}

xyz::xyz() : ModuleBase() {

}

Aucun commentaire:

Enregistrer un commentaire