Boost logo

Boost Users :

Subject: Re: [Boost-users] [regex] Boost.Regex + ICU vs. standalone ICU
From: John Maddock (boost.regex_at_[hidden])
Date: 2010-09-27 04:38:57


> That's fantastic, thank you. I have an unrelated Boost.Regex question: how
> expensive are basic_regex objects to copy? Say, relative to constructing
> (and
> thus reparsing) from a string pattern, anew?

A *lot* more efficient - basic_regex is a pimpl so it's just a shared_ptr
copy to copy a basic_regex.

> The reason I ask is because I have a variant type with several value
> types,
> including a regex type. I was wondering whether it makes more sense to
> store the
> regex pattern in that variant as a string, and to construct the actual
> basic_regex from that string every time I need to operate on it, or to
> store it
> as a basic_regex and hope that copies are not too expensive. One other
> alternative is to store the regex on the heap using a smart pointer, but
> I'd
> rather keep value semantics so long as performance isn't an issue.

No, don't construct every time you need it, that's just wasting CPU cycles
:-(

> (Oh, incidentally, does Boost.Regex have support for Boost.Serialization?
> Right
> now what I do is serialize it [the pattern] as an std::string -- is that
> the
> recommended approach?)

Yes, there's no explicit serialization support.

HTH, John.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net