
I am trying to use Boost.Filesystem and have run in to some issues with the API which may be actual problems or a lack of understanding on my part. 1) What is the generic way to create current directory and parent directory relative paths, e.g. "." and ".."? Currently for current directory I use boost::filesystem::path(boost::filesystem::path::string_type(1,boost::filesystem::slash<boost::filesystem::path>::value)) which is a bit verbose. Parent directory relative path is the same with '2' instead of '1'. Further, it presumes that string_type has a constructor taking a repeat count and a character which may not be true in all cases. I would define these functionally as path instances which, if passed to current_path, would stay in the same directory or move to the parent directory respectively. Is this usage too file system specific to be included in the library? Is there a superior way to create such paths? 2) Why isn't there a path constructor / generator which takes a pair of path element iterators? E.g. like path make_path(path::iterator x, path::iterator y) { path zret; for ( ; x != y ; ++x ) zret /= *x; return zret; } 3) I tried to write my own templated make_path but I don't see how to either use the path class as the template parameter or compute the path class from its iterator. That is, I want to use path::iterator x,y; // set somehow path p = make_path(x,y); Implemetation 1: template < typename Path > Path make_path(Path::iterator x, Path::iterator y) { ... } This fails because Path can not be deduced from the use of Path::iterator instances. Implementation 2: template < typename PathIter> ??? make_path(PathIter x, PathIter y) {...} I don't see how to specify the return type given the type of an iterator. I think it would be reasonable to put this in the iterator class typedef boost::BOOST_FILE_SYSTEM_NAMESPACE::basic_path<String, Traits> path_type; which would solve my problem. I was able to make it work with VC9 by adding this to the iterator definition in path.hpp typedef path_type path_type; // import from enclosing scope for clients but I don't know how portable that is. 4) My actual goal is to write the function path between(path here, path there) which returns a path such that after current_path(here); current_path(between(here,there)); this returns true equivalent(current_path(), there); and where the returned path is as relative as possible. This is very handy for file generation to generate # include "../inc/thing.h" instead of # include "C:/Documents and Settings/amc/view/main/inc/thing.h" If there is already an easy way to do that, I would be happy to be so informed. Thanks.

2009/7/2 Alan M. Carroll <amc@network-geographics.com>:
4) My actual goal is to write the function [...major snippage...] where the returned path is as relative as possible.
The bug requesting this functionality can be found here: https://svn.boost.org/trac/boost/ticket/1976 There's a naive implementation in the comments. I'd code up a proper version, but I need a symlink dereference function first.
participants (2)
-
Alan M. Carroll
-
Scott McMurray