Modify

Opened 16 years ago

Closed 15 years ago

#61 closed Bugs (Invalid)

regex iterator requirement

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

Description

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.
yours.

Attachments (0)

Change History (3)

comment:1 Changed 16 years ago by John Maddock

Logged In: YES 
user_id=14804

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

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.

regards,

John Maddock.

comment:2 Changed 16 years ago by lfarkas

Logged In: YES 
user_id=405207

thanks for the tipp again, but another bugreport in:
boost/regex/detail/fileiter.cpp
(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 != 
INVALID_HANDLE_VALUE); }
-----------------------------------
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 != 
INVALID_HANDLE_VALUE); }
-----------------------------------
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); }
-----------------------------------
yours.

comment:3 Changed 15 years ago by John Maddock

Status: assignedclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain John Maddock.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.