Boost logo

Boost :

From: Luke Stebbing (ls_at_[hidden])
Date: 2004-01-21 20:53:43


On Wed, 21 Jan 2004, "Daryle Walker" <darylew_at_[hidden]> wrote:
> Are Boost.Regex objects and strings semantically equivalent?
> ...
> From what little I know of Regex, I think the answer is "no". (So keep
> the constructor explicit.)

I agree that from an interface perspective, that's the primary question, but
I think the answer is "yes". Take a look at a string literal (char const*
const literal, technically):

"Hello world"

Conceptually, this is a string. On the other hand:

"He(\\w)+ world"

Conceptually, this can be considered as either a string or a regular
expression, depending on the context, and if a set of programmers were
selected and shown that literal, I believe the overwhelming response would
be "that's a regular expression".

A careful reader will note that "Hello world" is also a regular expression,
but a degenerate one (literal matching, no special characters) that we
usually just call a string. The primary attribute that distinguishes regular
expressions from stripped down const strings is where they are /used/, not
what they are. This is emphasized by the fact that aside from
locale/allocator information (which is associated with basic_string as well,
but in a different way) and mark_count (which is an inspector function that
gives information about parens grouping for a given regex), regex member
functions form a proper subset of string member functions and are
semantically identical.

Context gives a regular expression meaning, and if the danger of expensive,
accidental conversions is avoided (and I believe this is the case), implicit
conversions should be allowed.

- Luke Stebbing


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk