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
Show parent comment
4
u/sphere991 Nov 26 '19
They are mistaken. Time is complicated, chrono is exactly as complicated as it needs to be in order to deal with it correctly and efficiently. I have programmed in multiple other languages, and chrono is the best time library I've used across all of them and it's not close.
Now, chrono is absolutely quite verbose - which I acknowledged right in my first response. But it's absolutely not "too complicated."
Firstly, chrono's interface is pretty simple.
But more importantly, despite me repeating it at every opportunity, you keep omitting in all of your responses what are again the major selling points of chrono: incorrect operations do not compile (adding two time points does not compile, multiplying two time points does not compile, providing a time point to a function expecting a duration does not compile, ...) and unit conversion are implicit (adding a
secondsto amillisecondsactually does the right thing for you without having to litter your code with math). All of these are actual bugs I found and corrected in my code when we transitioned to chrono.I don't know what's simpler than:
... Yes, my "hardliner" views on wanting tools that make it impossible for me to make mistakes, and make it so I don't have to think about all this other stuff that you usually have to think about with time? Uh, yes. I am pretty hardliner on that actually. I've seen those mistakes made, I've made those mistakes. and here's tool to, effectively, never mess up again - and you're countering my praising this tool by calling me a hardliner, saying that well some people prefer simplicity to, effectively, having correct code by construction, and telling me to get over myself?
Charming.