Boost logo

Boost :

Subject: Re: [boost] [1.44] [filesystem] operator +
From: Scott McMurray ([hidden])
Date: 2010-08-25 12:16:58

On 25 August 2010 02:26, Jochen Wilhelmy <j.wilhelmy_at_[hidden]> wrote:
> path p = "foo/bar";
> path p1 = p + ".xml";-)
> path p2 = path(p1).replace_extension(".dat");

    path p1 = p.string() + ".xml";
    path p2 = p.string() + ".dat";

Since it's a string operation, not a path operation, I think that
doing it with string operators is better. It's not like the syntax
required is grotesque.

Personally, I'd prefer this version to make it even clearer what's
going on, and avoid any string parsing:

    path p1 = p.parent_path() / (p.filename() + ".xml");
    path p2 = p.parent_path() / (p.filename() + ".dat");

I also think that doing a string addition of a path with any string
containing a slash is a bad idea, and should be done with complete

If someone really wants to treat paths as strings, they can turn them
into strings. I don't see a reason to support string operations on
paths directly, since the conversions to and from strings are simple

~ Scott

Boost list run by bdawes at, gregod at, cpdaniel at, john at