$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] boost::filesystem request
From: Edward Diener (eldiener_at_[hidden])
Date: 2008-10-30 19:41:12
Beman Dawes wrote:
> On Wed, Oct 29, 2008 at 11:33 PM, Edward Diener <eldiener_at_[hidden]>wrote:
> 
>> Beman Dawes wrote:
>> ...
>> The issue for me was just ease of instantiation of a basic_path based
>> solely on a string type ( which is actually a character type ). One can not
>> currently instantiate a basic_path with:
>>
>> boost::filesystem::basic_path<std::basic_string<char>,
>> boost::filesystem::basic_trait<std::basic_string<char> > > myPath;
>>
>> where one just specifies the character type.
>>
>> Why would one want to do that ? For two reasons:
>>
>> 1) In a VC++ program which may be multibyte or Unicode depending on a
>> compiler option, we would have:
>>
>> boost::filesystem::basic_path<std::basic_string<_TCHAR>,
>> boost::filesystem::basic_trait<std::basic_string<_TCHAR> > > myPath;
>>
>> 2) A template class or template function taking a character type parameter
>> would just pass that type in to filesystem to instantiate the correct type
>> path.
>>
>> So I do not know whether your version 3 solves makes that easier or not,
>> but hopefully it does.
> 
> 
> Here is an example; this code does compile and run correctly under V3:
> 
> #include <boost/filesystem/path.hpp>
> #include <boost/filesystem/operations.hpp>
> #include <string>
> #include <cassert>
> #include <windows.h>
> #include <winnt.h>
> 
> namespace fs = boost::filesystem;
> 
> typedef std::basic_string<TCHAR> tstring;
> 
> void func( const fs::path & p )
> {
>   assert( fs::exists( p ) );
> }
> 
> int main()
> {
>   // get a path that is known to exist
>   fs::path cp = fs::current_path();
> 
>   // demo: get tstring from the path
>   tstring cp_as_tstring = cp.string<tstring>();
> 
>   // demo: pass tstring to filesystem function taking path
>   assert( fs::exists( cp_as_tstring ) );
> 
>   // demo: pass tstring to user function taking path
>   func( cp_as_tstring );
> 
>   return 0;
> }
It looks like you are saying that a boost::filesystem::path can be 
created from any string type and that one can retrieve the path as any 
string type. I can not think of any immediate objection to using 
boost::filesystem::path in this way, and it does simplify the use of it 
with different string types. This certainly seems like a worthwhile way 
to upgrade the library.