There have been requests for a Filesystem library relative function for at least ten years.

The requested functionality seems simple - given two paths with a common prefix, return the non-common suffix portion of one of the paths such that it is relative to the other path.

In terms of the Filesystem library,

    path p("/a/b/c");
    path base("/a/b");
    path rel = relative(p, base);  // the requested function
    cout << rel << endl;             // outputs "c"
    assert(absolute(rel, base) == p);

If that was all there was to it, the Filesystem library would have had a relative function years ago.

Critical issues: Clashing requirements, symlinks, directory placeholders (dot, dot-dot), user-expectations, corner cases.

A paper by Jamie Allsop, Additions to Filesystem supporting Relative Paths, is what broke my mental logjam. Much of [my proposal] is based directly on Jamie's analysis and proposal. The weakly_canonical function and aspects of the semantic specifications are my contributions. Mistakes, of course, are mine.

The full proposal is at http://boostorg.github.io/filesystem/relative_proposal.html

A preliminary implementation is available in the feature/relative2 branch of the Boost Filesystem Git repository. See github.com/boostorg/filesystem/tree/feature/relative2

The overall plan is to get feedback from boost developers, then merge to develop for boost 1.60, then propose to the C++ committee for addition to the Filesystem TS.

Comments welcome. If you are one of the many people who have requested "relative" functionality, does this proposal meet your needs? If not, why?

Thanks,

--Beman