Boost logo

Boost :

From: dylan_nicholson (dylan_nicholson_at_[hidden])
Date: 2002-02-25 21:20:29


--- In boost_at_y..., Beman Dawes <bdawes_at_a...> wrote:
> At 02:24 PM 2/25/2002, Jan Langer wrote:
>
> > - i currently implemented the classes with basic_ and typedef
to avoid
> >the char template parameter. is this ok?
>
> Sorry, I don't understand the question. I used "CharT" for the
name of the
> template parameter, because that is what it is called in the
standard's
> description of basic_string.
>

On an almost related note, there is a slight problem with only
supporting basic_string<T> for the filename - you can't pass char*
strings in - that is:

namespace filesystem
{
  template <class T>
  bool exists(const std::basic_string<T>& name);
}

int main()
{
  std::string filename1;
  filesystem::exists(filename1); // ok
  std::wstring filename2;
  filesystem::exists(filename2); // ok
  const char* filename3 = getfilename();
  filesystem::exists(filename3); // won't compile
  filesystem::exists("fixed_filename"); // won't compile
}

I think this could prove to be quite a nuisance.
One possibility is not to make filesystem a namespace but rather a
template class itself, and make all the functions static:

template <class T>
class basic_filesystem
{
  typedef std::basic_string<T> string;
  static bool exists(const string& name);
};
typedef basic_filesystem<char> filesystem;
typedef basic_filesystem<wchar_t> wfilesystem;

This way the main() function above should compile fine except for
filename2. I can't think of a situation where you would be likely to
be doing a mixture of char and wchar_t filesystem manipulation.

Hmm...the above seems a reasonable argument for template
namespaces...maybe Herb should add that one to his list?

Dylan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk