samedi 30 mai 2020

Send string literal as argument in C++ template - Parameter pack

My function declaration and implementation. It accepts variable number of arguments

template <typename... ParamType,
            typename = typename std::void_t<std::enable_if_t<std::is_same_v<ParamType, std::string> ||
                                                            std::is_floating_point_v<ParamType> ||
                                                            std::is_integral_v<ParamType>>...>>
static inline void Log(const ParamType &... args)
{
   //Implementation
}

I need to add support for cstrings(char *, const char *) and string literals.

Console::Log("Non std::string literal"); //ERROR (const char [24])
Console::Log("hola %s %s %d %s"s,"helloWorld"s,"Joma"s,1, 1990); //OK
Console::Log<String, String, String,int, int>("hola %s %s %d %s"s,"helloWorld"s,"Joma"s,1, 1990); //OK

Aucun commentaire:

Enregistrer un commentaire