我想寫一個函數,可以使用C++ 0x的type_traits功能處理char & wchar_t。是的,我知道如何在沒有type_traits的情況下做到這一點,但我希望使用type_traits來更好地理解該功能。是否可以使用type_traits區分char&wchar_t?
template <typename T>
void SplitIt(T* base, T* ext, const std::basic_string<T>& fullFilePath, std::true_type)
{
_splitpath(fullFilePath.c_str(),NULL,NULL,base,ext);
}
template <typename T>
void SplitIt(T* base, T* ext, const std::basic_string<T>& fullFilePath, std::false_type)
{
_wsplitpath(fullFilePath.c_str(),NULL,NULL,base,ext);
}
template <typename T>
std::basic_string<T> GetBaseName(const std::basic_string<T>& fullFilePath)
{
T base[300], ext[50];
SplitIt(base, ext, fullFilePath, /*What goes here?*/);
return std::basic_string<T>(buf) + ext;
}
int main()
{
std::basic_string<TCHAR> baseName = GetBaseName(std::basic_string<TCHAR>(__FILE__));
}
是否有任何type_traits屬性區分char和wchar_t?
Pff,簡單的解決方案! ...我很慚愧,甚至沒有想到... :( – Xeo
輝煌!雖然它應該是is_same在我的代碼。謝謝。 –
Sharath
@Sharat:對,修正它... – MartinStettner