Boost logo

Boost :

Subject: Re: [boost] [xpressive] Is there a way to test for an empty regex?
From: Eric Niebler (eric_at_[hidden])
Date: 2008-11-19 16:47:54


Michael Goldshteyn wrote:
> What is the best way to test for an empty boost::xpressive::regex object?
>
> That is, if I have code like:
>
> boost::xpressive::sregex re;
>
> ...
>
> // Test if re is empty and should not be used to perform a regex_search
> if (?????)

There is, although it's not obvious from the documentation that it's
possible. You can see from the postcondition on the default constructor
of basic_regex that this->regex_id() == 0 for default-constructed regex
objects and != 0 for non-default constructed regex objects. So your test
above can be:

if( 0 != re.regex_id() )

HTH,

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

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