3 ms·
What is wrong with that syntax?
by pkaye 6y ago
What is wrong with that syntax?
- jcelerier 6y ago? nothing is wrong, it's just a different way to spell template<typename T> void F(T p) { ... }
- moocowtruck 6y agocan i say T : SomeConstraint ?
- jcelerier 6y agoin C++ ? sure template<SomeConstraint T> void F(T p) { ... } or just void F(SomeConstraint auto p) { ... } like this for instance: https://gcc.godbolt.org/z/hPM38T https://gcc.godbolt.org/z/hPM38T
- moocowtruck 6y agocool, can i even add two constraints? or is it limited to one. Oh i see you have include concepts, is that new to c++20 then?
- esarbe 6y agoNo, not acually. Generics in Go are vastly different than templates in C++. They might be used for similar things, but whereas Go's generics actually build up on Go's structural typing, templates are ... something completely different again. I mean; C++ templates are Turing complete. They are in the same ballpark as Scala's type machinery. And I say that with adoration.
- jcelerier 6y ago> I mean; C++ templates are Turing complete. that's not a very high milestone to achieve. Even java generics are turing complete (https://arxiv.org/abs/1605.05274 https://arxiv.org/abs/1605.05274)
- esarbe 6y agoHoly crap, indeed! The older I get, the more icky I find subtyping. It just makes things messy...