Live data from Hacker News

An introduction to C++'s variadic templates: a thread-safe multi-type map

jguegant.github.io

11–19 of 19 posts

Re: An introduction to C++'s variadic templates: a thread-safe multi-type map

#11
post #10

I do most of my work in C# now, and templates are what I miss most from C++. The syntax is, well, horrible, but the things you can do really help eliminate what would otherwise be redundant code. Just make sure you comment the hell out of things like this or the people that have to read and maintain your code later will hate you.

I see it as a language in itself. Once done with the steep learning curve you start to observe repeated patterns and get it more easily. I do agree that the syntax is a huge drawback from now.

Re: An introduction to C++'s variadic templates: a thread-safe multi-type map

#12
post #10

I do most of my work in C# now, and templates are what I miss most from C++. The syntax is, well, horrible, but the things you can do really help eliminate what would otherwise be redundant code. Just make sure you comment the hell out of things like this or the people that have to read and maintain your code later will hate you.

If you've been away from C++ for a while I'd recommend revisiting it. Some C++14 features greatly improve the syntax when working with templates: auto return type deduction is a huge simplifier for example. Alias templates are very helpful too and generic lambdas come in handy.

Variadic templates add new syntax but they make some previously very tedious things relatively trivial once you understand the syntax.

C++17 will bring some further improvements when writing templates. Concepts lite will be a huge deal but there are a number of other niceties too, some already available in clang.

Re: An introduction to C++'s variadic templates: a thread-safe multi-type map

#13
post #10

I do most of my work in C# now, and templates are what I miss most from C++. The syntax is, well, horrible, but the things you can do really help eliminate what would otherwise be redundant code. Just make sure you comment the hell out of things like this or the people that have to read and maintain your code later will hate you.

I see it as a language in itself. Once done with the steep learning curve you start to observe repeated patterns and get it more easily. I do agree that the syntax is a huge drawback from now.

Yup, it's definitely its own language! It made me so happy when I saw a Haskell-to-C++-template compiler [1] because of all the similarities in pure-FP style (pattern matching, iteration via recursion, etc).

[1] https://gergo.erdi.hu/projects/metafun/

Re: An introduction to C++'s variadic templates: a thread-safe multi-type map

#14
post #10

I do most of my work in C# now, and templates are what I miss most from C++. The syntax is, well, horrible, but the things you can do really help eliminate what would otherwise be redundant code. Just make sure you comment the hell out of things like this or the people that have to read and maintain your code later will hate you.

[deleted]

Re: An introduction to C++'s variadic templates: a thread-safe multi-type map

#15
This is vaguely reminiscent of a SO comment I ran across recently: http://stackoverflow.com/a/27962571, which really opened my eyes to the powerful combination of variadic templates and tuples. OP's guide is very informative in breaking things down, kudos; but I also suggest checking out that SO comment as it's a more barebones exposition of variadic templates + tuples (no threading, no watching, etc).

Re: An introduction to C++'s variadic templates: a thread-safe multi-type map

#16
post #13

Earlier quoted context omitted.

I see it as a language in itself. Once done with the steep learning curve you start to observe repeated patterns and get it more easily. I do agree that the syntax is a huge drawback from now.

Yup, it's definitely its own language! It made me so happy when I saw a Haskell-to-C++-template compiler [1] because of all the similarities in pure-FP style (pattern matching, iteration via recursion, etc). [1] https://gergo.erdi.hu/projects/metafun/

Haskell and C++ look like the "elite" combo these days, especially when it comes to meta-programming and FP as you said! It's funny how these two different communities are mixing. It feels like JavaScript and Ruby having a child.

Re: An introduction to C++'s variadic templates: a thread-safe multi-type map

#17
post #8

This is an excellent write-up on some really great additions to the C++ language that make type-safe programming more flexible.

Thank your Sir! Sadly C++ drags a bad reputation from its earlier years. I wish my posts make C++ reachable and enjoyable for common guys like me.

In a somewhat misspent youth, I was a grad student of Jaakko Järvi when he and the rest of the Indiana folk were pitching variadic templates and concepts. I was browbeat into attempting to add concept constrained variadic templates to GCC. So... it turns out, for this problem, for precise constraints, the number of constraints is strongly exponential (factorial of factorials). I think we ended up going with the intersection of all the concepts, instead; which totally sucked & made constrained variadic templates pretty useless.

I suppose it doesn't matter since the concepts proposal was torpedoed. (But that's another story.)

Re: An introduction to C++'s variadic templates: a thread-safe multi-type map

#18
post #17
post #8

Earlier quoted context omitted.

Thank your Sir! Sadly C++ drags a bad reputation from its earlier years. I wish my posts make C++ reachable and enjoyable for common guys like me.

In a somewhat misspent youth, I was a grad student of Jaakko Järvi when he and the rest of the Indiana folk were pitching variadic templates and concepts. I was browbeat into attempting to add concept constrained variadic templates to GCC. So... it turns out, for this problem, for precise constraints, the number of constraints is strongly exponential (factorial of factorials). I think we ended up going with the inter…

I yet didn't check the proposal for C++17 concepts, it seems to constantly change since C++11. Does it includes anything related to variadic templates? Anyway, you must have had a lot of fun with Jaakko Järvi as a teacher!

Re: An introduction to C++'s variadic templates: a thread-safe multi-type map

#19
post #17

Earlier quoted context omitted.

In a somewhat misspent youth, I was a grad student of Jaakko Järvi when he and the rest of the Indiana folk were pitching variadic templates and concepts. I was browbeat into attempting to add concept constrained variadic templates to GCC. So... it turns out, for this problem, for precise constraints, the number of constraints is strongly exponential (factorial of factorials). I think we ended up going with the inter…

I yet didn't check the proposal for C++17 concepts, it seems to constantly change since C++11. Does it includes anything related to variadic templates? Anyway, you must have had a lot of fun with Jaakko Järvi as a teacher!

I don't know---I finished my PhD 7 years ago & never really got back into the ISO stuff. Jaakko was (and is!) fantastic.
Post reply on HN