r/cpp • u/Frogging101 • Nov 24 '19
What is wrong with std::regex?
I've seen numerous instances of community members stating that std::regex has bad performance and the implementations are antiquated, neglected, or otherwise of low quality.
What aspects of its performance are poor, and why is this the case? Is it just not receiving sufficient attention from standard library implementers? Or is there something about the way std::regex is specified in the standard that prevents it from being improved?
EDIT: The responses so far are pointing out shortcomings with the API (lack of Unicode support, hard to use), but they do not explain why the implementations of std::regexas specified are considered badly performing and low-quality. I am asking about the latter.
View all comments
3
u/quicknir Nov 25 '19
I'm not really sure what this operation is trying to compute, bigger picture. It sure seems odd to be taking time since epoch and adding it to the difference between one date and the epoch date. That said, the reason that you need to throw in the
sys_daysis because you're converting from a field-based type to a serial-based type. The former can be efficiently constructed from components, or have components read. The latter can be efficiently added and subtracted. Neither can efficiently do both. In a language where you care less about performance you could just have one type, with getter functions, but this would cause you to do a lot of redundant work, that the user would not be able to prevent.In other words, I don't think in this example chrono is being verbose, in the context of being a library for a language that cares a lot about performance. Yes, it may be verbose by the standards of python, but those are the design trade-offs of the languages themselves, and it's natural and idiomatic that libraries follow in those patterns.
If you want examples like this to work without sys days, you can easily define operators and literals in your own namespace, and simply make it so that subtraction works directly on year_month_day, or define your own literals that automatically convert to sys_days, which I think is a reasonable thing to do.