
First; pre-emptive apologies if this should be sent to boost-users instead of here (or I guess the Mod can nuke it and tell me). I figured I should send it here because it's more of a design issue than a "how do I use this" issue... path::begin() is defined as returning an 'iterator' (not a const_iterator), so I figured I'd be able to write to it. I wrote some code which did something like: fs::path p; /*...*/ for (fs::path::iterator it = p.begin(); it != p.end(); it++) if (*it == "FOO") *it = "BAR"; This errors because operator* on the iterator type returns a const string&. So: was this a deliberate design decision? I don't see anything about this in the design rationale stuff in the docs for Boost.Filesystem. Is there a good reason not to allow people to use the iterator to modify individual path elements? -- Jordan DeLong fracture@allusion.net

"Jordan DeLong" <fracture@allusion.net> wrote in message news:20050601032618.GA23098@allusion.net...
First; pre-emptive apologies if this should be sent to boost-users instead of here (or I guess the Mod can nuke it and tell me). I figured I should send it here because it's more of a design issue than a "how do I use this" issue...
path::begin() is defined as returning an 'iterator' (not a const_iterator), so I figured I'd be able to write to it.
The docs describe iterator as " A const iterator..."
I wrote some code which did something like:
fs::path p; /*...*/ for (fs::path::iterator it = p.begin(); it != p.end(); it++) if (*it == "FOO") *it = "BAR";
This errors because operator* on the iterator type returns a const string&.
So: was this a deliberate design decision? I don't see anything about this in the design rationale stuff in the docs for Boost.Filesystem. Is there a good reason not to allow people to use the iterator to modify individual path elements?
Doing so would require actually maintaining elements internally as individual elements, say in a vector of strings. That would be pretty inefficient for most uses of path, just to support such uncommon usage. Instead, rewrite your code something like this: fs::path p; /*...*/ fs::new_path new_p; for (fs::path::iterator it = p.begin(); it != p.end(); it++) if (*it == "FOO") new_path /= "BAR"; else new_path /= *it; HTH, --Beman

"Beman Dawes" <bdawes@acm.org> writes:
"Jordan DeLong" <fracture@allusion.net> wrote in message news:20050601032618.GA23098@allusion.net...
First; pre-emptive apologies if this should be sent to boost-users instead of here (or I guess the Mod can nuke it and tell me). I figured I should send it here because it's more of a design issue than a "how do I use this" issue...
path::begin() is defined as returning an 'iterator' (not a const_iterator), so I figured I'd be able to write to it.
The docs describe iterator as " A const iterator..."
I think the correct term is "a constant iterator," unless you mean that it returns something of type const iterator -- Dave Abrahams Boost Consulting www.boost-consulting.com

"David Abrahams" <dave@boost-consulting.com> wrote in message news:uis0xudw7.fsf@boost-consulting.com...
"Beman Dawes" <bdawes@acm.org> writes:
"Jordan DeLong" <fracture@allusion.net> wrote in message news:20050601032618.GA23098@allusion.net...
First; pre-emptive apologies if this should be sent to boost-users instead of here (or I guess the Mod can nuke it and tell me). I figured I should send it here because it's more of a design issue than a "how do I use this" issue...
path::begin() is defined as returning an 'iterator' (not a const_iterator), so I figured I'd be able to write to it.
The docs describe iterator as " A const iterator..."
I think the correct term is "a constant iterator," ...
Fixed. Thanks! --Beman
participants (3)
-
Beman Dawes
-
David Abrahams
-
Jordan DeLong