Boost logo

Boost Users :

Subject: [Boost-users] [filesystem] basic_path as paramter
From: Alexander Lamaison (awl03_at_[hidden])
Date: 2010-03-08 20:28:40


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 becuase basic_path has a second Traits template
paramter 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 paramter type. Does
anyone know how I can get this to work?

Many thanks.

Alex Lamaison


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net