
AMDG Alex Lamaison wrote:
I'd like to use basic_path as a function parameter so that it works correctly whether a wide or narrow string is passed.
template<typename T> void func(basic_path<T> file) { do thing to file }
func("myfile"); func(L"myfile");
However I can't do this because basic_path has a second Traits template parameter which is not itself a template. So I tried the following workaround:
template<typename T> struct traits_chooser;
template<> struct traits_chooser<char*> { typedef boost::filesystem::path_traits traits; };
template<> struct traits_chooser<wchar_t*> { typedef boost::filesystem::wpath_traits traits; };
template<typename T> void func(basic_path<T, typename traits_chooser<T>::traits> file) {...}
But my compiler (MSVC 2005) still can't deduce the parameter type. Does anyone know how I can get this to work?
Try specializing for char and wchar_t instead of char* and wchar_t*. You could also just use template<typename T, typename Traits> void func(const basic_bath<T, Traits>& file); In Christ, Steven Watanabe