Templates, man.
Templates, man.
A good perspective.
From the ref:
---
Conclusion
We attempted to represent ownership and borrowing through the C++ type system, however the language does not lend itself to this. Thus memory safety in C++ would need to be achieved through runtime checks.
Example code
#include <type_traits>
#include <utility>
#include <assert.h>
#include <stddef.h>
Templates it must be.
#include <boost/spirit.hpp>
using namespace boost;
int main() {
spirit::rule<> group, fact, term, expr;
group = '(' >> expr >> ')';
fact = spirit::int_p | group;
term = fact >> *(('*' >> fact) | ('/' >> fact));
expr = term >> *(('+' >> term) | ('-' >> term));
assert( spirit::parse("2*(3+4)", expr).full );
assert( ! spirit::parse("2*(3+4", expr).full );
}
https://studylib.net/doc/10029968/text-processing-with-boost... slide 40What's C++ and what's regex?
(That's why it's great that Haskell and other languages in that family allow you to define your own operators, instead of eg re-using bit-shifting for IO.)
(Btw, parsing C++ is already Turing complete.)
The root cause is that template expansion is duck-typed. 'Concepts' are supposed to fix that, I heard.
That still doesn't help if you want the fields names.
But you are right that C++ templates are a bad functional programming language with duck typing.