News for hackers. Stuff that matters.
Re:A brief guide to C++ template metaprogramming by qwertyuiop924 on Sunday September 25, 2016 @08:25AM (#12575025)
Implementing generics was a good idea. However, templates were not. They should have been dismissed as a bad job years ago, and replaced by a better metaprogramming facility with less complexity, if at all possible (given the complexity of C++, it may not be). Kind of like what Rust did, by pretty much just stealing syntax-rules wholesale from Scheme.
Re:A brief guide to C++ template metaprogramming by webreac on Sunday September 25, 2016 @09:54AM (#12575314)
I have discovered generics with the Ada language (yes, I am old). When learning C++ template, my first feelings were that it was an insane inconsistent hack. Many C++ compilers struggle during many years before standard was reasonably well supported. Standards have also evolved and consistency was guaranteed.

C++ template is an incredibly complex but also flexible and powerful beast that has no equivalent apart maybe the macro system of scheme. C++ templates allows to change the semantic of the program as if the language was changed. Genericity is just a special case of usage of C++ template. Its true nature is to extend the C++ language.

Re:A brief guide to C++ template metaprogramming by qwertyuiop924 on Sunday September 25, 2016 @10:23AM (#12575443)
...The difference is, Scheme's macro system (syntax-rules: there are others) is elegant and simple, whereas C++ templates are still an insane inconsistant hack. They're just a standard insane, inconsistant hack.

But the other thing about the Scheme macro system is that while its (relative) simplicity, elegance, safety, and power lead to its adoption by other languages (most famously, JS (in the form of an external preprocessor) and rust), it's actually quite underpowered by Lisp standards, and thus most implementations provide a nonstandard system for hygenic imperative macros, usually either er/ir macros, sc/rsc macros, or syntax-case. Of the three, I'd say syntax-case is an overly complex mess, and that the other two both have merits.

So since TMP is doing similar substitutions (AFAICT: I haven't done the deep dive) to syntax-rules, it's got very real, and relatively common, limits. And as C++ slowly expands in scope, it will have to deal with problems that syntax-rules has already solved (what if a function creates a lambda or takes a function pointer argument called ioctl, and your template expansion calls ioctl?), and TMP hasn't AFAICT.

And even when they fix all that, they'll still have C++, which is about as regular as the Linux Kernel relase schedule combined with The DevTeam's.

Re:A brief guide to C++ template metaprogramming by gpderetta on Monday September 26, 2016 @06:23AM (#12580634)
Templates are quite complex for sure, but certainly not an hack.

They are also unlike scheme macro system which works at the AST level; C++ templates work at the type level, which scheme lacks entirely[1].

> what if a function creates a lambda or takes a function pointer argument called ioctl, and your template expansion calls ioctl?

Are you talking about macro hygiene? C++ templates are hygienic, except for type dependent lookup which intentionally isn't.

Re:A brief guide to C++ template metaprogramming by qwertyuiop924 on Monday September 26, 2016 @06:39AM (#12580705)
Ah, so there is hygene. I couldn't tell, so I assumed not.
Re:A brief guide to C++ template metaprogramming by fiddlerwoaroof on Sunday September 25, 2016 @06:30PM (#12577800)
Recently, I was looking into Ada and the way its generics worked was quite eye-opening.