Suppose I have this function for trimming std :: string and deciding whether to expand it, so that it removes not only spaces from beginning to end, but also any character that I pass on another line, such as spaces, characters new line and carriage return.
std::string Trim ( const std::string &In_Original,
const std::string &In_CharsToTrim = " \n\r" );
Basically, it will remove all characters present in In_CharsToTrim from the beginning and end of In_Original.
Now I had to write this for both std :: string and std :: wstring. Since I find this absurd, I decided to use templates, and it works, but I can not pass the default value, because the version of std :: wstring should get L" \n\r"as the default value (note that there is little L there).
I tried this:
template <typename Type> Type Trim ( const Type &In_String,
const Type &In_TrimCharacters );
together with:
template std::string Trim ( const std::string &In_String,
const std::string &In_TrimCharacters = " \n\r" );
template std::wstring Trim ( const std::wstring &In_String,
const std::wstring &In_TrimCharacters = L" \n\r" );
. .
, , , , :
template <typename Type> Type Trim ( const Type &In_String,
const Type &In_TrimCharacters );
std::string Trim ( const std::string &In_String );
std::wstring Trim ( const std::wstring &In_String );
, Trim, .
, , , , ...:
? , , ...
std::string ( " \n\r" ) std::wstring ( L" \n\r" ) ...
... , , ?