Re: [boost] [1.44] [filesystem] operator +

Sometimes I have file formats that have two parts, e.g. a description xml file and a data file. then I'd like to do name + ".xml" and name + ".dat" if name is a fs::path
path p1 = "foo/bar.xml"; path p2 = path(p1).replace_extension(".dat");
path p = "foo/bar"; path p1 = p + ".xml";-) path p2 = path(p1).replace_extension(".dat");

On 25 August 2010 02:26, Jochen Wilhelmy <j.wilhelmy@arcor.de> 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 instead. 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 enough. ~ Scott
participants (2)
-
Jochen Wilhelmy
-
Scott McMurray