Opened 17 years ago

Closed 16 years ago

#61 closed Bugs (Invalid)

regex iterator requirement

Reported by: lfarkas Owned by: John Maddock
Milestone: Component: regex
Version: None Severity:
Keywords: Cc:


regex require that iterator (eg for regex_match) has 
default constructor. AFAIK it's not a requirement for 
any (neither bidirectional) iterator to has a default 
constructor. eg for user defined iterator sometime it's 
a preformance decrease for iterator. eg. I'd like to
use regex to search a file. if the file fit into the 
memory I use wstring's iterator, but if not I have to 
create an own bi_istream_iterator (since 
std::istream_iterator is not bidirectional:-(). after 
that I made an iterator which encapsulate these two
iterator, but this hasn't deafult constructor and if I 
have to make a default one, than I'have to redesign it 
and add another bool member. what I realy wan't that 
the encapsulator iterator be as samll as possible, but 
it's getting harder and harder:-(((
IMHO it's a bug in regex implementation.

Change History (3)

comment:1 Changed 17 years ago by John Maddock

Logged In: YES 

The standard requires all ForwardIterators and above to 
have a default constructor (see C++ standard, Table 74), 

WRT your particular problem - have a look at the mapfile 
class in boost/regex/detail/fileiter.cpp - this will either 
use a memory mapped file (on win32), or else use smart 
iterators to load sections of a file into memory as 
required - it may be close enough to what you need, or at 
least give you some ideas.


John Maddock.

comment:2 Changed 17 years ago by lfarkas

Logged In: YES 

thanks for the tipp again, but another bugreport in:
(which would be usefult to make public anyway)
in mapfile (for win32) the following member should have to 
be const:
   const char* begin(){ return _first; }
   const char* end(){ return _last; }
   size_t size(){ return _last - _first; }
   bool valid(){ return (hfile != 0) && (hfile != 
the correct form:
   const char* begin() const { return _first; }
   const char* end() const { return _last; }
   size_t size() const { return _last - _first; }
   bool valid() const { return (hfile != 0) && (hfile != 
and if I send it to you another cosmetic fix. I always 
prefere member initilaization over assigment:
   mapfile(){ hfile = hmap = 0; _first = _last = 0; }
   mapfile(const char* file){ hfile = hmap = 0; _first = 
_last = 0; open(file); }
my prefered version:
   mapfile() : hfile(0), hmap(0), _first(0), _last(0) {}
   mapfile(const char* file) : hfile(0), hmap(0), _first(0), 
_last(0) { open(file); }
and for the unix version:
   mapfile(){ hfile = 0; _size = 0; _first = _last = 0; }
   mapfile(const char* file){ hfile = 0; _size = 0; _first = 
_last = 0; open(file); }
the new ones;
   mapfile() : hfile(0), _size(0), _first(0), _last(0) {}
   mapfile(const char* file) : hfile(0), _size(0), 
_first(0), _last(0) { open(file); }

comment:3 Changed 16 years ago by John Maddock

Status: assignedclosed
Note: See TracTickets for help on using tickets.