I tried to declare a function that converts const char * to std::basic_string in the following way:
#include <string>
#include <cstring>
#ifdef _MSC_VER
#include <tchar.h>
#else
#define TCHAR char
#endif
typedef TCHAR Char;
typedef std::basic_string<Char> String;
template <typename = typename std::enable_if< !std::is_same<Char, char>::value >::type >
inline String FromACString(const char * p_src)
{
String dest(std::strlen(p_src), ' ');
auto p_cur = p_src;
for (auto & ch : dest)
{
ch = *p_cur++;
}
return dest;
}
template <typename = typename std::enable_if< std::is_same<Char, char>::value >::type >
inline String FromACString(const char * p_src)
{
return p_src;
}
but got compiler errors. My idea was to have two overloads and enable one of them depending on TCHAR type. What is the proper way to do this?
The error with VC2017 is:
error C2995: 'String FromACString(const char *)': function template has already been defined