> After constructing and checking the sentry object, if rdbuf() is not null, calls rdbuf()->sputbackc(ch), which calls rdbuf()->pbackfail(ch) if ch does not equal the most recently extracted character.
I would imagine some people would like it if their iterators for IO streams could be anything from random access to bidi to forward, depending on where they got it from.
Just grabbing what you want explicitly seems better.
A network stream is not replayable so no forward iterators. It can be made replayable, but then that functionality should probably go as generic iterator wrappers since it can be applicable to any similar construct.
So in the end what we need to do to parse a file sensibly is to open the file, read the entire contents into a string (which first mmaps the file, which allocates memory and virtual address space, and then copy all that into malloc'd buffer, which allocates memory and virtual address space again) instead of just using the (useless) iterators.
It'd behave basically like a segmented iterator, where each segments has a control node that keeps a shared pointer to a buffer segment and to the next control node.
@R.MartinhoFernandes I feel like the root of this problem is that the streams library is virtually (lol) the only dynamically polymorphic piece of the standard library. :P
@Griwes Though if you go and mimic the iterator concepts in streams, I question the stream/iterator distinction (at least as the idea of "stream" as it currently stands in the library) in the first place.
I always feel like the stream library has too much overlap with the iterator library.
(Well, with way too many libraries. Locale et al. But not something I want to focus on)
IMO it should just be raw I/O and perhaps some basic buffer management facilities.
I wonder if this could be extended to bidirectional iterators for the file case (I know it could not sanely for network streams, but for files?).
Sounds like more logic, but I think the amount of logic stays about the same.
Hmm.
Or even random access (though that'd be much harder on bookkeeping, since you'd have gaps in your segmented iterator thing).
auto file = open("asdf"); auto it = file.seek(1024); ++it; peek(it); is fully reasonable IMO; not sure if giving the option to do it += 10000; would make sense (especially since you already have seek).
@Griwes If you want you can avoid the extra logic with two read modes, one where you can only read forward (call it "streaming") and one where you can read back too (name?)
Hey guys I've got a problem. I have an implementation file and a header file with declarations. In the declaration file I have a template function, example:
Quote from The C++ standard library: a tutorial and handbook:
The only portable way of using templates at the moment is to implement them in header files by using inline functions.
Why is this?
(Clarification: header files are not the only portable solution. But they are the most convenien...
@Griwes Is the dynamic polymorphism bit really so bad? After all, there's a lot of code that handles the base classes of std:: streams and then uses those.
Granted, they probably do that because it's the only way right now, but I would imagine a lot of developers are thankful they don't have to nail their choice down to a specific type of stream (see the FILE* fiasco of many C APIs which for some reason only take a FILE* file pointer or a const char* fname c-string, and usually have to be hacked up later to deal with a section of memory or otherwise).
> First, and not limited to concepts, we need to treat a member template as dependent if its signature depends on template parameters of its enclosing class […]
@R.MartinhoFernandes Now what about the other direction? How do you do writes? And more importantly, how do you connect that with async IO? Or is the async IO layer just the layer that the iterators build upon?
I guess for "synchronous" writes you could make it possible to write through those iterators, and that's okay, but async IO needs to be an actual thing (though it probably should be the layer below).
Would need a way to flush all the changes done through iterators.
@ThePhD how is it any more gross than something = *it;?
auto file = open("asdf"); auto it = file.seek(1024); ++it; peek(it); is fully reasonable IMO; not sure if giving the option to do it += 10000; would make sense (especially since you already have seek).
There's a bit more of discussion and random attempts at online design in the discussion above.
If you could write an IO layer beneath that that allowed you not to be forced to move forward or backwards when doing a read or write that'd be the first part of making iterators more viable, right?
It'd behave basically like a segmented iterator, where each segments has a control node that keeps a shared pointer to a buffer segment and to the next control node.
These are the two messages most important for understanding what I'm getting at, I think.
@ThePhD Vapor, sitting on top of an UEFI bootloader and a brand new greenfield kernel following it, sitting on top of a CPU toyed with in Verilog (where I'm currently mostly fighting with the language), sitting on top of Despayre (which's my build system thingy), sitting on top of constant improvements to my general purpose libraries.
@Ell Well, if you've never seen code that thinks that getc (+ ungetc after failed peek...) is a right interface to use when parsing text, then you'll keep missing it.
If you've seen such code, you are probably hating it and hoping to forget it ever existed one day.