Products > Programming

C++ Template Meta Programming for regular expressions?

(1/2) > >>

westfw:
As I understand things, regular expressions require that the standard format we're used to be "compiled" into an FSM before actual processing occurs.  I'm curious whether anyone has written a C++ library that does the FSM generation at compile time rather than during execution (presumably using template meta programming?)

Ash:
It is possible, and there is a pretty amazing library under development:

https://github.com/hanickadot/compile-time-regular-expressions

I've not used it, but I've been following its development.. there are a number of CppCon videos on Youtube about it.

*edit* Just a warning you will need a modern compiler.. C++17 minimum I think.

Enjoy,
Ash.

magic:
It's such a basic problem I'm sure there are tools which take regular expression and spit out a C function which recognizes it.

SiliconWizard:
As it's possible to program a Tetris game with C++ templates apparently, what you're after should be perfectly possible. I don't know of any such available solution, but I'm sure it's possible.

Apart from performance reasons, what would be your rationale for using that as opposed to a generic regex library? Code size I suppose?

Edit: just found this: https://github.com/NTSFka/template_regex

Cerebus:

--- Quote from: magic on November 11, 2019, 10:14:34 pm ---It's such a basic problem I'm sure there are tools which take regular expression and spit out a C function which recognizes it.

--- End quote ---

Since the very earliest versions of Unix, it's called 'lex'. Not the easiest thing to use, but it's there and pretty much always has been.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version