Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2004-01-21 16:47:05


On 1/14/04 6:31 PM, "Luke Stebbing" <ls_at_[hidden]> wrote:

>>> Why is regex's constructor explicit? Certainly for something like vector,
>>> you don't want the size constructor to turn into a conversion from int.
>
>> Constructing a regex is generally an expensive operation, so it's explicit to
>> ensure that regular expressions are only created when the user really means
>> it.
>
> Unlike the fundamental and standard types, regex doesn't appear in standard
> functions, and only has a few operator overloads. In fact, string's overloads
> form a proper superset. The only functions where the regex type appears are
> the regex utility functions themselves, and it seems unlikely that a user
> would accidentally construct a regex with them.
>
> Are there any examples where a user might inadvertantly construct a regex from
> a string, were the constructor implicit?

I haven't used regex; just seen the stuff posted about it here. Let's take
this from a pure interface standpoint.

//=======================================================================
Are Boost.Regex objects and strings semantically equivalent?
//=======================================================================

If so, then conversions should be allowed and the constructor should be
implicit. If not, i.e. a string is just a configuration parameter that
happens to be by itself, then the constructor should stay explicit.

>From what little I know of Regex, I think the answer is "no". (So keep the
constructor explicit.)

An "explicit" should mark "I'm a configuration routine, not a conversion
one". IMO, just simply not appearing any circumstances where conversion
could occur is NOT justification for switching (off) the "explicit"
attribute.

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT hotmail DOT com

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