|
Boost : |
Subject: Re: [boost] [filesystem] Request for comments on proposed relative() function
From: Beman Dawes (bdawes_at_[hidden])
Date: 2014-05-08 13:19:51
On Thu, May 8, 2014 at 1:13 PM, Paul A. Bristow <pbristow_at_[hidden]>wrote:
> > -----Original Message-----
> > From: Boost [mailto:boost-bounces_at_[hidden]] On Behalf Of Beman
> Dawes
> > Sent: 08 May 2014 16:58
> > To: Boost Developers List
> > Subject: [boost] [filesystem] Request for comments on proposed
> relative() function
> >
> > There are two open tickets requesting a relative() function, and also a
> National Body
> > (I.E official) comment against the Filesystem TS (which is due to
> finalize at the June
> > C++ committee meeting). The committee's Library Working Group has
> indicated they
> > would like to add such a function.
> >
> > With help from Jamie Allsop, I've put together a proposal. See attached
> for docs
>
> I couldn't read the attached docs :-(
>
Hum... Not sure what the problem is, but here they are inline:
8.6.3 path relative function [path.relative]
path relative(const path& p, const path& base);
Creates a path from the trailing elements of p that are relative to base.
*Effects:* If the number of elements in [p.begin(), p.end()) is less than
or equal to the number of elements in [base.begin(), base.end()), or if any
element in [base.begin(), base.end()) is not equal to the corresponding
element in [base.begin(), base.end()), throw an exception of type
filesystem_error.
*Remarks: *Equality or inequality are determined by path::operator== or
path::operator!= respectively.
*Returns: *An object of class path containing the first element of p that
does not have a corresponding element in base, followed by the subsequent
elements of p appended as if by path::operator/=.
*Throws:* filesystem_error.
[*Note:* The behavior of relative is determined by the lexical value of the
elements of p and base - the external file system is not accessed. The case
where an element of base is not equal to corresponding element of p is
treated as an error to avoid returning an incorrect result in the event of
symlinks. *--end note*]
*A possible implementation would be:*
auto mm = mismatch( p.begin(), p.end(), base.begin(), base.end());
if (mm.first == p.end() || mm.second != base.end())
{
throw filesystem_error(
"p does not begin with base, so can not be made relative to base",
p, base,
error_code(errc::invalid_argument, generic_category()));
}
path tmp(*mm.first++);
for (; mm.first != p.end(); ++mm.first)
tmp /= *mm.first;
return tmp;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk