Boost logo

Boost :

Subject: Re: [boost] boost::filesystem::path frustration
From: Eric Niebler (eniebler_at_[hidden])
Date: 2013-01-27 17:48:31


On 1/25/2013 3:54 PM, Dave Abrahams wrote:
>
> on Fri Jan 25 2013, Eric Niebler <eniebler-AT-boost.org> wrote:
>
>> On 01/25/2013 08:30 AM, Beman Dawes wrote:
>>> Not particularly elegant, but this does work:
>>>
>>> path x("/foo/bar");
>>> path y("/foo/baar");
>>>
>>> auto result = std::mismatch(x.begin(), x.end(), y.begin());
>>>
>>> path prefix;
>>> for (auto itr = x.begin(); itr != result.first; ++itr)
>>> prefix /= *itr;
>>
>> I believe this last bit is just std::accumulate with std::divides<path>.
>> Whether that better expresses intent is another matter.
>
> Seriously, no. I have no problem using / for path construction, but
> "divides" means division.

struct append_path : std::divides<path> {};
path prefix = std::accumulate( x.begin(), result.first, path(),
append_path() );

:-)

-- 
Eric Niebler
Boost.org
http://www.boost.org

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