TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Compile time regular expression in C++

72 pointsby Tideflatover 1 year ago

10 comments

burntsushiover 1 year ago
I&#x27;d love for someone to add this to rebar[1] so that we can get a good sense of how well it does against other general purpose regex engines. It will be a little tricky to add (since the build step will require emitting a C++ program and compiling it), but it should be possible.<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;rebar">https:&#x2F;&#x2F;github.com&#x2F;BurntSushi&#x2F;rebar</a>
评论 #37515880 未加载
daeminover 1 year ago
It&#x27;s a good library but be careful as it can significantly increase compile times. I added a couple of reasonably long regular expressions to a c++ source file and it increased the compile time from near instant (below to 1 second) to 30 seconds. Might be wise to move these to dedicated source files so you don&#x27;t pay this penalty each time you make changes.
nlyover 1 year ago
Boost Xpressive has had static&#x2F;&quot;compile time&quot; regex in C++ since the mid 2000s<p><a href="https:&#x2F;&#x2F;www.boost.org&#x2F;doc&#x2F;libs&#x2F;1_83_0&#x2F;doc&#x2F;html&#x2F;xpressive.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.boost.org&#x2F;doc&#x2F;libs&#x2F;1_83_0&#x2F;doc&#x2F;html&#x2F;xpressive.htm...</a><p>A performance comparison would be interesting.
评论 #37517101 未加载
aruncover 1 year ago
D has ctRegex since a decade ago <a href="https:&#x2F;&#x2F;dlang.org&#x2F;phobos&#x2F;std_regex.html#ctRegex" rel="nofollow noreferrer">https:&#x2F;&#x2F;dlang.org&#x2F;phobos&#x2F;std_regex.html#ctRegex</a>
arijunover 1 year ago
At the risk of sounding like an idiot, what is the benefit of being able to match at compile time?
评论 #37516722 未加载
评论 #37516442 未加载
cracauerover 1 year ago
C++ finally catches up to Perl :-)
emmanueloga_over 1 year ago
Since people is posting other lang implementations... someone did it for zig too (probably less polished than this C++ lib) [0]. It is nice that the regexes can be used at compile time too [1].<p>--<p>0: <a href="https:&#x2F;&#x2F;github.com&#x2F;alexnask&#x2F;ctregex.zig">https:&#x2F;&#x2F;github.com&#x2F;alexnask&#x2F;ctregex.zig</a><p>1: I think the difference between C++ template language and Zig comptime is that Zig&#x27;s comptime is almost equal as Zig&#x27;s regular language, whereas the experience of programming C++ templates almost feels like learning a separate, equally complex language.
nemoniacover 1 year ago
This has been available in Lisp since at least 2004.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;edicl&#x2F;cl-ppcre&#x2F;">https:&#x2F;&#x2F;github.com&#x2F;edicl&#x2F;cl-ppcre&#x2F;</a>
评论 #37515190 未加载
评论 #37518507 未加载
评论 #37515167 未加载
docandrewover 1 year ago
This has been a part of the dlang standard library for some time: <a href="https:&#x2F;&#x2F;dlang.org&#x2F;phobos&#x2F;std_regex.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;dlang.org&#x2F;phobos&#x2F;std_regex.html</a>
ape4over 1 year ago
Hopefully the standard regex will be constexpr soon.
评论 #37513457 未加载
评论 #37516916 未加载