CppCast - Boost Hana

Episode Date: April 13, 2016

Rob and Jason are joined by Louis Dionne to discuss C++ metaprogramming with Boost Hana. Louis is a math and computer science enthusiast with interest in C++ (meta)programming, functional prog...ramming, domain specific languages and related subjects. He is an active member of the Boost community, and recently wrote the Boost.Hana metaprogramming library. News Synth - Semantic syntax highlighting and code hyper-linking tool for C and C++ C++Now 2016 Program Highlights: Performance Talks Logical Expressions in C/C++ Mistakes made by professionals Louis Dionne Louis Dionne's Blog @louisdionne Links Boost Hana C++Now 2016 - Metaprogramming for Dummies C++Now 2016 - Metaprogramming for the Brave CppCon 2015 - C++ Metaprogramming: A Paradigm Shift

Transcript
Discussion (0)
Starting point is 00:00:00 This episode of CppCast is sponsored by Undo Software. Debugging C++ is hard, which is why Undo Software's technology has proven to reduce debugging time by up to two-thirds. Memory corruptions, resource leaks, race conditions, and logic errors can now be fixed quickly and easily. So visit undo-software.com to find out how its next-generation debugging technology can help you find and fix your bugs in minutes, not weeks. CppCast is also sponsored by CppCon, the annual week-long face-to-face gathering for the entire C++ community.
Starting point is 00:00:33 Get your ticket now during early bird registration until July 1st. Episode 53 of CppCast with guest Louis, recorded April 13th, 2016. In this episode, we talk about logical expressions and a new libclang tool. Then we talk to Louis Dion, author of Boost Hannah. Louis tells us how Hannah differs from Boost's other metaprogramming libraries. Welcome to episode 53 of CppCast, the only podcast for C++ developers by C++ developers. I'm your host, Rob Irving, joined by my co-host, Jason Turner. Jason, how are you doing today? Doing good, Rob. How about you?
Starting point is 00:01:49 Doing pretty good. I wanted to share that we're up to over 2,000 followers on Twitter now. I thought that was pretty cool. Yeah, that's like six times more than I have. Yeah, it's more than I have, too. I guess people are more often following the podcast than they are the two of us. Which is funny, because I think the two of us both tweet a lot more than the show does. Yes, maybe that's why they're more interested in following the show than us.
Starting point is 00:02:21 Yeah, well, feel free to follow all three of the accounts. Anyway, at the top of our episode, I'd like to read a piece of feedback. This week, I got two reviews on iTunes. First one from SportsScoreJunkie wrote, great podcast about what's going on in C++. And the second from ReadTime says, awesome C++ podcast. I've been looking for a C++ podcast
Starting point is 00:02:42 for a very long time. This is just exactly what I hoped for to keep me up to date with what's going on in the C++ community. So thanks for those kind words and the five-star reviews. We really appreciate that. And we love to hear your thoughts about the show as well. You can always reach out to us on Facebook, Twitter, or email us at feedback at cppcast.com. So joining us today is Louis Dion. Louis is a math and computer science enthusiast with interest in C++ metaprogramming, functional programming, domain-specific languages, and related subjects. He's an active member of the Boost community and recently wrote the Boost HANA metaprogramming library. Louis, welcome to the show. Thank you. Thanks for joining us.
Starting point is 00:03:22 So we just had a couple things to go over before we start talking about Boost HANA and some of your other work. Feel free to comment on any of these articles we wanted to bring up. Jason, I'll let you introduce the first one on Synth. What is a Synth library? It's a tool that's based on libclang. And as you know, I'm a huge fan of tools. And I'm a big fan of people doing interesting things on libclang and as you know uh i'm a huge fan of tools and i'm a big fan of people doing interesting things with libclang so this guy uh made a project that will just take
Starting point is 00:03:50 your c++ source and generate a hyperlinked html files from it using libclang to generate all the hyperlinking nice and and i looked at the output that he made with uh the library itself or the tool itself and it looks like it's nice and color-coded HTML, so it's very pretty to look at. Yeah, it's pretty clean. It'd be kind of interesting, you know, if something like GitHub could do this kind of thing automatically so you could automatically click between your source files and stuff.
Starting point is 00:04:19 But I thought our listeners might be interested in it. I think it would be interesting if it could be integrated into, you know, like a mainstream documentation generation tool, let's say into Doxygen, because right now Doxygen does not support modern C++ very well. So, I mean, I don't know, but writing HANA's documentation, I often found myself, you know, fighting against Doxygen bugs, and it was just really annoying. I wish there was proper syntax, I proper syntax for modern C++ especially.
Starting point is 00:04:49 Well, it might be a good point to mention what DoxyPress is the update to Doxygen that's being worked on by some people that is supposed to make better C++11. Okay, then I should just get informed. And this was actually brought up in a comment, how is this tool different from Doxygen? And the author pointed out it's not a documentation generator. It's just for getting your code into HTML, right?
Starting point is 00:05:15 I know, I know. I wish it could be integrated into a documentation generator. Yeah. Okay, the next one is from the C++ Now website, and they're doing a blog post about some of the talk highlights. And this one is on three performance talks that are going to be at C++ Now this year. And the first one is from our very own Jason Turner. Yep. And this is going to be your talk on practical performance practices.
Starting point is 00:05:41 What are you going to be going over in this talk jason um in general just talking about how writing simpler cleaner code can is almost always faster code so the the well i mean i'm gonna it's a bunch of different topics i'm gonna be covering actually i'm almost afraid that i might have too much information to cover but in general leading to simpler, more idiomatic ZOS Plus with the goal of getting faster code. And I'm going to be covering my experiences with ChaiScript and doing that. Nice. And then the two other talks that are mentioned here, one is from David Stone, who was another
Starting point is 00:06:17 past guest of the show. I think we had him on to talk about his bounded integer library. Is that right? Yeah. Yeah. And there's one from, and by the the way his talk is called exceptional performance and the other one is from sebastian reddell and his talk is diet for your templates reducing code bloat in your templated library and we have not had sebastian on the show but maybe we should reach out to him
Starting point is 00:06:42 i think this talk is going to be awesome. While it might not seem like an actual issue for most mainstream developers, for library authors, code bloat is actually a huge problem. Sometimes when you use a lot of templates, it's going to generate a lot of long symbol names
Starting point is 00:07:02 and it's going to end up in the final executable unless you do link time optimization, but I don't think it's always done. And the other thing is, it's actually a real problem that I've come across. I don't know whether Sebastian will be covering this, but it's nasty. If you write the same code over and over,
Starting point is 00:07:22 say, to process each member of a user-defined struct, obviously, the compiler is just going to write the same code over and over, say, to process each member of a user-defined struct, obviously, like, the compiler is just going to write the same code over and over because you're, like, hard-coding it. Now, it works fine if you have, like, three members, but with metaprogramming, you can often end up with huge user-defined structs because a tuple is just a user-defined struct.
Starting point is 00:07:42 So you end up sometimes, like, like with 100 members and you have the same code being generated over and over for the 100 members and it creates a huge amount of bloat. It would be awesome if the optimizer was able to re-roll the loop and to make it into an actual loop, you know, which would be much faster. So it's the kind of
Starting point is 00:08:00 challenges that we have in metaprogramming and I don't know whether Sebastian will talk about this, but it's definitely a deep topic. That's what I mean. Yeah, I was planning to attend all three of these talks myself already. Yeah. Very cool. So this last one is from the PVS Studio developers, and it's an article about some of the mistakes
Starting point is 00:08:23 made with logical expressions and reading through this article it you know first talks about some mistakes you might make with conditional operators and i know i've probably made some of these mistakes myself how about you jason uh yes it makes me want to do a full audit of chai script to see where i'm making these mistakes yeah yeah um and the cool thing about this article is how he, you know, shows you what the problem is. And then he shows an actual case in,
Starting point is 00:08:51 you know, something like I think he has, yeah. From the free free BSD project, an example of some of these conditional mistakes. So, you know, these errors are really out there and they're definitely worth looking for.
Starting point is 00:09:06 Yeah. To improve your code. And then there's also a note at the bottom about improper use of the ternary operator. And this was something I definitely didn't know about, that the ternary operator has some of the lowest priority when evaluating a line of code. And you can definitely get into some bad behavior or some unexpected behavior when using it. Yeah. I personally generally lean away from using ternary anyhow, but it does make me wonder in the cases where I have used it. I like the ternary operator, but I think I do usually stick to just assigning it as a single line of code
Starting point is 00:09:44 and not kind of combining it in a larger expression and that's where you can get into trouble with it, it looks like. Yeah. Louis, is there anything you wanted to comment on with this one? Oh, well, no. Well, not really. I mean, the ternary operator, sometimes you have to use it in
Starting point is 00:09:59 constant expressions, you know, before C++14, so you don't really have the choice there. But no, apart from that. Okay, so you're going to be speaking at C++ Now this year. You actually have two talks planned, metaprogramming for dummies and metaprogramming for the brave, right? Yeah. And you're going to be talking mostly about Boost HANA.
Starting point is 00:10:19 Can you tell us a little bit about it? Oh, yeah, sure. So HANA is a metaprogramming library. It's a C++14 metaprogramming library. So conceptually, it's basically HANA provides containers and algorithms to work on containers, a bit like the standard library. But the similarity really stops there because the design, the implementation, and the purpose of HANA is completely different from that
Starting point is 00:10:45 of the stdlib. The containers provided by HANA are, you know, so like the containers provided by the standard library are generic containers that can contain arbitrary number, finite, of course, numbers of objects of the same type. Now, NS containers can contain objects that have different types, but the number of types that are going to be in the container has to be known. So basically
Starting point is 00:11:14 NS containers are like tuples, so you know what are the types of each element and you know the number of types and then you create your container. And where it pushes further than the standard
Starting point is 00:11:29 library is that it also provides different kinds of data structures. Instead of only having a tuple, like std tuple, it also has a heterogeneous map, it has a heterogeneous set, it has a range, a compile time string and stuff like that.
Starting point is 00:11:47 So basically instead of having std vector, you have hana tuple, where the elements of the container can have different types. And it's not related to polymorphism at all. The static type of the elements are actually known by the compiler. And does that make sense i think so you said a heterogeneous set right that's right yeah i'm trying to wrap my mind around what exactly that means because the set is a unique object so can you have more than one object of the same type in your heterogeneous set how do they compare to each other? How does that work? They have to be comparable at compile time
Starting point is 00:12:26 because the set enforces the uniqueness of the keys inside it. Since the objects may have different types... Basically, all the objects in the set must have different types.
Starting point is 00:12:42 When you compare any two objects, they must return a std integral constant that says whether they are equal. And we also have something to do, some compile-time hashing. It's used in the map right now, not in the set implementation, but it's really like a std on-ordered set
Starting point is 00:13:00 where you have a compile-time hash and also you use a compile-time comparison to compare different objects. And then you can test whether some thing is inside the set or not. You can insert and do stuff like that. So it can be useful for, well, compile-time stuff, right? And now, so Ana provides containers, a bit like the standard library, but heterogeneous.
Starting point is 00:13:27 And it also provides algorithms, like I said. But instead of having algorithms that operate on ranges of elements delimited by iterators, such as a stdlib, ANA's algorithms will operate directly on the heterogeneous data structures. So the kind of thing that you can do is sort a tuple based on a predicate that is known as compile time.
Starting point is 00:13:51 Of course, you need it to be known as compile time because the result will be a new tuple. But since the elements can have different types, the order of the elements in a resulting tuple has to be known as compile time because it's going to affect the type of the result of the elements in the resulting tuple has to be known at compile time because it's going to affect the result of the type of the result of the sort function. So you're talking
Starting point is 00:14:10 about sorting the types in the tuple, not sorting the values contained in the tuple. I am, okay, I am talking about sorting the values based on the types of these values or an information derived from their type
Starting point is 00:14:27 because you could have an arbitrary predicate. So the kind of thing that you can do is have a tuple and then sort it based on the size of the types in the tuple. So if you have a char, a nint, and then a long double inside a tuple, you can, in whatever order, you can sort long double inside a tuple, you can, in whatever order, you can sort the values inside the tuple based on the size of the type of these objects. So, as I'm trying to wrap my mind around this,
Starting point is 00:14:57 could you, for instance, write an algorithm or does the HANA already contain an algorithm that would let you um sort the types in a tuple so that it is more efficiently packed yes that is possible it does not contain that but it's one example that i gave in a previous talk at some point yeah okay all right interesting that's the kind of thing that you can do uh now okay sort is a bit tricky because it interacts like there's an interaction between the runtime and the compile time, which is a bit hard to understand. Now, you can also do more mundane stuff like just reverse a tuple.
Starting point is 00:15:30 You have a tuple, and you just reverse the elements in it. It's essentially the same principle. And you can partition a tuple based on a predicate that is not at compile time and stuff like that. Now, the difference between the standard library algorithms and HANA's algorithms is obviously that because of their heterogeneous nature, HANA's algorithms will be executed partly at compile time and partly at runtime. So like I said, if you sort the comparison,
Starting point is 00:16:00 comparing the pairs of elements inside your tuple is going to be done at compile time, then once the final ordering of your tuple is determined, it's done at compile time. Now, once that is determined, you're going to need to create the resulting tuple with the tuple that contains the values inside the original tuple, but in the right order that you just computed at compile time. Now that copying is going to have to happen at runtime.
Starting point is 00:16:30 It just can't be otherwise. So it's like partly runtime, partly compile time. And of course, if you're sorting trivial stuff that, say, if you're sorting std strings based on something at compile time, then there might be some costs but if you're sorting just like integers in most cases the optimizer will do a good job and
Starting point is 00:16:52 will just you know just not copy anything around right so yeah that's basically it's like a standard library but for metaprogramming both with values and with types interesting there are other existing library, but for metaprogramming, both with values and with types. Interesting.
Starting point is 00:17:10 There are other existing Boost metaprogramming libraries, right? How would you say HANA compares to some of the existing offerings in Boost? Right. So metaprogramming libraries fall into two bold categories. There are those that can manipulate types, and there are those that can manipulate values. So the Boost MPL can manipulate types. Say you have a bunch of types, you have an MPL vector, you stick your types into your MPL vector, and then you MPL transform your vector using a meta function, and then that gives you back a new MPL vector with the result of the transformation.
Starting point is 00:17:46 Now, there's Boost Fusion, which is also like a metaprogramming library that works with values, but it only works with values. So you can have a fusion vector, which is essentially exactly the same
Starting point is 00:18:02 as a std tuple, basically, or a hana tuple. And, or a HANA tuple. And then you can do a bunch of runtime computations like for each. You can also transform a fusion vector with a runtime function. It's just going to map the function over each element in the vector, which, remember, is just a tuple, and give you back your resulting tuple. Now, the difference is that HANA falls into both categories. It can be used both for value manipulations and type manipulations.
Starting point is 00:18:34 The reason is that, well, it only provides facilities for dealing with values, but it also provides a way to express types and computations on types as objects and and once you have that once you have this representation of types as objects you can just take your types which are not objects and just take them into tuples and then you can manipulate them as if they were normal objects so So instead of having like MPL transform and fusion transform, there's just ANA transform which can manipulate values and types. And I mean, it can manipulate values,
Starting point is 00:19:13 but then you take your types, represent them as values, and do the work you have to do into the value world. And it turns out that it has many advantages because expressing computations and types using a value syntax is more natural because value syntax is just... When I say value syntax, I really mean just normal C++ syntax.
Starting point is 00:19:34 It's just like instead of writing a meta function with a struct, with a templated struct, you're going to write a lambda or just a function object. So it's much cleaner. And yeah, instead of using like MPL plus, you're just using, you're going to use just a plus operator on your stood integral constant.
Starting point is 00:19:54 And well, on your HANA integral constant, it's going to work. So the difference really is that it can do all that MPL and fusion could do using just half of the facilities because of this way of representing types and type computations as values. So it just brings up the level of expressiveness. So if it can do everything that MPL and Fusion can do, then what's the future for those projects? Are you superseding them? Right. So since HANA is only supported by a few cutting edge compilers,
Starting point is 00:20:34 these libraries will still, at least on a short term basis, they still definitely have their place. But in the long term, I do believe that these libraries will be replaced by HANA. But don't get me wrong. There are great libraries and they were both pioneers for something really important in C++. They both
Starting point is 00:20:57 explored something that was they were the first in their domain. They were super useful and well-designed, but now the language has evolved so much that we can do better in terms of compile time, in terms of expressiveness, in terms of simplicity of implementation. I mean, if you look at the Boost.mpl, it's incredibly complicated.
Starting point is 00:21:23 And what they're actually doing isn't complicated. It's just that they work around compiler hacks all the time. Right. I mean, compiler bugs. They work around compiler bugs all the time. So yeah, we can do better. So I think they're going to be replaced. But now I would like to add a caveat to that.
Starting point is 00:21:42 Although Anna can, in theory, do anything that MPL and Fusion did, if you have really, really intensive pure type-level computations, so MPL-style computations on types, you might find yourself having compile time performance that is slightly not what you would expect with ANA because ANA uses the value encoding to perform the type of computations that asks a bit more from the compiler and it causes the compile times to be higher.
Starting point is 00:22:23 So it's not higher than MPL or Fusion. It's much better than that. But if you compare it to a modern metaprogramming C++ library that would have been designed specifically for type-level computations, such as Brigand that you received on the show a while back, Brigand is going to be faster. It's like lightning fast. Whereas Ana will be a bit slower
Starting point is 00:22:47 at compile time, of course. So what I would advise is that if you can try using Ana because their level of expressiveness and their ease of use is in my opinion, higher, if you find that the compile times are too bad for you,
Starting point is 00:23:07 then you could use something faster that is more tailored to your specific use of type-level computations. But you're going to lose some expressiveness, but it's going to be lightning fast. Since you brought up compiler support in there, I'm guessing when you say modern compilers, Visual Studio
Starting point is 00:23:27 2015 is not currently supported? Nah. Unfortunately, it's, you know, so playing version 3.5 and up, Apple's playing 3.5, yeah. That's pretty old, yeah.
Starting point is 00:23:43 It's like maybe a year or something like that, maybe two years. Apple's clang since Xcode 6.3. Before then, they used just something that was older than 3.5, and it wouldn't work. And GCC 6, basically GCC trunk right now. So, yeah. And while GCC 5.x is advertised as having full C++14 support, unfortunately, the support is so buggy that it's not really useful. There are many problems with variable templates,
Starting point is 00:24:17 generalized constant expressions, and stuff like that. So, I mean, I know it means that HANA cannot be realistically used in most production code, but it's just the limit we... I mean, I use the full C++ working language, so if you don't support it, I'm sorry. So can you give a specific example to put you on the spot for what kind of GCC bug you've hit? Oh, right. Say you, okay, there is one bug that I think they are fixing right now, or maybe they have fixed it. But like, if you have, it's going to be a bit difficult to explain.
Starting point is 00:25:02 But basically, it was inside a generalized constant expression. I was comparing like a, I was having iterators, well, pointers, right, to some data. And then I was comparing these pointers in the loop saying like, while first is not equal to last and then increment first you know and just a classic thing in i was basically just re-implementing a constexpr i think it was to partition or something like that okay and and um i think it was like when the the the first was equal to last it would say that the comparison was not a constant expression because it was like comparing an out-of-bounds pointer or something like that.
Starting point is 00:25:52 Now, that's like a... And I think it would work if you reverse the comparison, like last not equal to first and stuff like that. So it's just like there was a couple of broken things. You would also get like linker errors if you use variable templates with, I think, a lambda. You define a variable template, which is equal to some lambda, and then you call the lambda. It gives you a linker error. So a bunch of things like that.
Starting point is 00:26:24 I think I have like 15 bug reports or something. Yeah, I mean, I have a lot of bug reports for Clang 2. They were just fixed much quicker. Wow. I haven't looked at the chart in a while, but I know
Starting point is 00:26:39 MSVC is getting closer and closer to full 11 and 14 support. Which features are they lacking that are preventing HANA from being able to run there? I don't know by heart all the specifics of this compiler, but
Starting point is 00:26:55 I know that two-phase lookup would be great. But I think they have big problems with supporting expressions FINAE. I believe that's still implemented. Yeah. Okay.
Starting point is 00:27:12 Well, if that's not there then it just won't work. But I would say basically good support for generalized constexpr, perfect support for expressions FINAE, variable templates, but that's probably there.
Starting point is 00:27:28 I don't know. I think it's there now. In all cases, it's easy to implement, so it's probably not a problem. I mean, from a compiler design point of view. And apart from that, I would say naively that we should be able to work around,
Starting point is 00:27:43 you know, we should be able to work around most two-phase lookup problems in HANA, like to support them. I mean, if they were really, really close to, you know, supporting HANA, I could also work on my part to, you know, introduce a couple of compiler workarounds. Not too many because I'm trying to keep the codebase clean, but I mean, if it can, you know, make the ANA
Starting point is 00:28:09 much more useful to a wider audience, then it would be worth it. So, basically, yeah, I would say generalized constant expressions, good support for that, and perfect support for expressions. FINA is very important. Apart from that, we can work. I'm guessing your best bet would be to try the Clang front-end for MSVC.
Starting point is 00:28:27 Oh, yeah, that works. Oh, yeah, I forgot to mention it. It actually works, yeah. So it works on Windows. It's tested on the app layer. It works using the Clang front-end. Okay. I wanted to interrupt this discussion for just a moment
Starting point is 00:28:48 to bring you a word from our sponsors. You have an extensive test suite, right? You're using TDD, continuous integration, and other best practices, but do all your tests pass all the time? Getting to the bottom of intermittent and obscure test failures is crucial if you want to get the full value from these practices.
Starting point is 00:29:09 And Undo Software's live recorder technology allows you to easily fix the bugs that don't otherwise get fixed capture recording of failing tests in your test suites and debug them offline so that you can collaborate with your development teams and customers get your software out of development and into production much more quickly and be confident that is of higher quality visit undo-software.com to see how they can help you find out exactly what your software really did as opposed to what you expected it to do and fix your bugs in minutes, not weeks.
Starting point is 00:29:37 So can you tell us a little bit more about what you're going to be going over in the metaprogramming for dummies talks? Yeah. So basically, I will try to explain what is metaprogramming for dummies talks? Yeah. So basically, I will try to explain what is metaprogramming from the ground up. I will also try to explain how to do it, what it can be used for.
Starting point is 00:29:55 And really, the thing that is special about this talk is that it does not expect any prior knowledge of metaprogramming. So it should really be for dummies. And yeah, it's going to use the new paradigm brought by Anna, which is of using value-level syntax to manipulate types instead of the classical approach, which is of using template-based struct,
Starting point is 00:30:25 which we call metafunctions, to do the work. So I think metaprogramming can be taught in a fairly straightforward manner. One has to take the time to explain it properly from the ground up, which, unfortunately, I didn't have that time in that show. But I think it can be explained in a straightforward manner, and especially without too many syntactical hacks, template type name everywhere, column, column type. I'm trying to get away from this.
Starting point is 00:31:05 So yeah, basically the goal will be to explain what is metaprogramming, how it can be done, how it can be used, and why you shouldn't be afraid of it anymore using HANA, because that's my tool. So it's going to be my first attempt to teach it. Wow, sounds interesting. I hope it's going to work as you know, it could be
Starting point is 00:31:28 a flop too, I don't know. I hope it's going to work well. The C++ Now audience of course won't have any dummies in it. I know, I know. I know, but then I plan, I'm not sure yet, but I plan to maybe
Starting point is 00:31:42 submit the talk, a slightly modified version of the talk, to CppCon. Right. Which hopefully might have a bit more dummies, but I mean, still, CppCon, anybody who goes to C++ conference is not a dummy, of course. I know that, but maybe... When I mean dummy, I mean dummy with respect to metaprogramming.
Starting point is 00:32:08 Yes, we know what you mean. Which is not really being a dummy at all. So your second talk, then, metaprogramming for the brave, is that build from the first talk? No. Okay, so this one is actually a candy for myself and the other
Starting point is 00:32:24 attendees. It's going to be a talk about just dirty C++ tricks. Unless you're a library author, you don't want to be there. But if you're a library author, you really want to be there. It's basically like dirty metaprogramming techniques used inside HANA to make the compile times quicker. And to help the optimizer figure out what can I do with this piece of code. So it's like all to reduce bloat, all to make your code more optimizable. But really from a metaprogramming library author point of view. So a lot of incredibly tricky uses of constant expressions, stuff like interacting between the compile-time world and the runtime world. Yeah, just also using C++ features
Starting point is 00:33:23 in a way that you would have never thought of doing, like fancy usages of lambda expressions, of lambda functions. And yeah, it's going to be just like a big gathering of tricky and dirty tricks for metaprogramming. I think it's going to be, it's really specifically tailored for the C++ Now audience. I think it's going to be great, and I'm really excited to discuss all the ideas there with
Starting point is 00:33:54 the other attendees. It sounds like a talk that you'll get a lot of the audience asking you questions and pushing you. Oh yeah, I'm actually preparing not that much material i mean i know i mean i know i understand i understand but but i i understand that most uh a big part of the talk should be interaction with attendees explaining like what the hell is this uh and and stuff like that so um this this talk I will definitely not do at any other conference in SQL Swift now.
Starting point is 00:34:27 Yeah, for our listeners who have not been to this conference, it is great for audience interaction if you want that. By the way, I don't know whether you were going to say it in the show, but I would like to plug it. I think there are a couple of places left for the conference. If you hear this, you should really jump on the tickets while there are still some. They didn't pay me to say that. Personally, this conference changed my life. Maybe it could change yours um end of the plug yeah i know last week we mentioned that
Starting point is 00:35:07 there were like under 20 seats left i'm not sure what that number is now i think it might be under 10 or something but anyway just check it out if you have some interest this conference is just great yes so um maybe going back to the content you probably have planned for the dummies talk uh can you think of a good practical example of why someone might want to use HANA if they're a C++ developer who hasn't really thought much about metaprogramming? Right. Okay, so I won't lie to you. Metaprogramming still is slightly more useful for library authors than it is for application developers,
Starting point is 00:35:51 mostly because of the lack of proper reflection for C++. When we have proper reflection, I believe that it will be much more useful for application developers. Now, a classical example that could be useful to an application developer would be just to make repetitive quotes shorter and more maintainable. So say you have something to do over a fixed set of types, like registering classes.
Starting point is 00:36:19 Well, you could probably use a macro in some sense or in some way, or you could also use just just a hana for each on a on a tuple of that contains your types and then do your registration or whatever on on on on your on each type now um another thing is serialization uh basically every application developer i know of has a you know a need for serialization at one point or another. Now, I can make this much easier. Like I've presented in a previous talk, I presented maybe like under 100 lines of code that would make automatic JSON generation from arbitrary user-defined types. Unfortunately, because of the lack of proper reflection, you still have to use a macro when you define your user-defined type.
Starting point is 00:37:11 That sucks, but I'm pretty sure that we'll have a better answer for this in the future. So that's the kind of thing that can be useful. And for just, say, application developers now, other big areas of application are, of course, domain-specific languages, expression templates, and generic libraries in general. But this is more like a niche audience. Yeah, and the nice thing about metaprogramming in C++
Starting point is 00:37:41 is that basically all the work is done at compile time. So you can use-program, you can use meta-programming even in a performance-sensitive application. Whereas, say, in Ruby or Python, all the meta-programming happens at runtime. And I know you won't write anything, you know, performance-critical in these languages anyway. But still, I mean, it's good to know that you can raise your level of expressiveness, of maintainability by using meta-rogramming when it makes sense without incurring any runtime overhead, in theory, at least. Right. So when you're writing HANA, you're having to push the compiler in all kinds of ways. We just talked about the fact that you
Starting point is 00:38:20 can only really support Clang. What would you say is your most underappreciated feature of C++? Or if you'd prefer your most hated feature of C++? Or both. I don't think I... Well, I would have to give a thought to the most hated feature. I don't know. But definitely... Oh, yeah, I do know.
Starting point is 00:38:43 Oh, yeah. Okay, anyway, let's not get into this. I really hate the type name. I know it's, you know, having to type type name before. Oh, having to type the actual keyword. I mean, I know it's necessary to disambiguate in some situations,
Starting point is 00:38:58 but it's really painful. Anyway, but I think my like the most underappreciated feature, but I think my, like, the most underappreciated feature, but I'm not sure whether it's really underappreciated or whether it's just too new to have had the time to be appreciated properly, but generic lambdas. Generic lambdas are, like, especially for metaprogramming, they're, like, they're incredible. They are very powerful
Starting point is 00:39:26 and they allow us to write things much more concisely than we would have been able to do it before. So yeah, I think their generic lambdas are like, I know they're just sugar, right? But they're very, very nice sugar. And otherwise, we would always have to write to write
Starting point is 00:39:49 function, out-of-line function objects, which is really, really annoying. So generic lambdas, I would say. And, you know, of course, constexpr, but constexpr is like a no-brainer, but constexpr and generic lambdas are like, wow.
Starting point is 00:40:08 Okay. I think that's all I got, got jason you have any other questions today uh no i think that's all i have although maybe just a quick note that there was a talk at last year's c++ now called generic lambdas from scratch which i have not yet watched but it could be informative to our listeners who just got intrigued by the idea of generic lambdas. Okay. Well, Louis, where can people find more information about Hannah, find more information about you online? Oh, well, about me on my website, which I believe you should publish in the show notes, ldeon.com.
Starting point is 00:40:42 I have a small blog. And on HANA, well, on the GitHub page, which is now github.com, boost.org, HANA. And yeah, basically everything's there. And by the way, I would like to mention that HANA will be released with Boost
Starting point is 00:40:58 in Boost 1.61, which should be, which is currently in beta. It's almost there, and once it is there, you will just have to pull in boost to get HANA. I think it's nice. Excellent. Great. It's been great having you on the show today.
Starting point is 00:41:17 Thank you. It was great to be there. Thanks for joining us. Thanks so much for listening as we chat about C++. I'd love to hear what you think of the podcast. Please let me know if we're discussing the stuff you're interested in, or if you have a suggestion for a topic, I'd love to hear that also. You can email all your thoughts to feedback at cppcast.com. I'd also appreciate if you can follow CppCast on Twitter and like CppCast on Facebook. And of course, you can find all that info and the show notes on the podcast website at cppcast.com.
Starting point is 00:41:49 Theme music for this episode is provided by podcastthemes.com.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.