I’m going to be at GDC talking about… Deep Learning applications! No C++ at all! Incredible, isn’t it?
Continue reading GDC 2017C++
Despite the name, perfect forwarding is not so perfect. In the following example, a class B is constructed by passing a : struct A { int x, y; }; struct B { B(A a) { /*…*/ } }; int main() { B b1({1, 2}); } Everything’s ok: {1, 2} is deduced to be the …
Continue reading Not-so-perfect forwardingLast Saturday I’ve been giving two presentations about C++11&14 I originally wrote for NVIDIA internal tech talk at C++ User Group in Udine meetup, invited by Nicola Gigante (@gignico). It has been a very nice meetup, with a lot of nice people, and I’m willing to join them again in the future, if possible. During the first one, …
Continue reading LSIL,TTNG (Last Saturday I Learned, Thanks to Nicola Gigante…)This post is also available in Italian. Note to self: Never try to modify your examples in realtime during a presentation, to show an idea that just came through your mind: You might succeed. The problem We have an old pre-C++11 class: As you can see, class C contains a function get() which returns a …
Continue reading Optimizing return valuesThis post is also available in Italian. As stated in a previous post, final keyword enables the sealing of classes and methods. This is important because it allows interesting compile-time checks, but also enables quite a powerful optimization: the devirtualization. Devirtualization happens when the compiler can statically decide, at compile time, which function should be called, so it can produce …
Continue reading The power of devirtualizationI’m not posting anything since GDC, and the reason is that I’m not working on C++ very much lately, because I’m quite busy in trying to make some sense out of the shamanic art they call deep learning. Luckily I’ve been invited to talk at the Italian C++ Day in Firenze on October 29th (http://www.italiancpp.org/event/cppday16/, …
Continue reading A digression…NOTE (2016/03/26 01:30PM): The content of this post has has been fixed. I must thank Lawrence Crowl for pointing out my mistake at SG14 GDC 2016 meeting. It is well known that using ordering comparison operators (<, <=, >, >=) with mixed signed/unsigned types result in warnings and, ultimately, in undefinedunexpected behaviour. I never loved this, and I …
Continue reading Signed/Unsigned operations and undefined behaviourDiscussing with another C++ programmer, we came out with this piece of code: #include <iostream> template <class… Args> void foo(int, Args…) { std::cout << “1”; } template <class…Args> void foo(Args…, int) { std::cout << “2”; } int main() { foo(11); // A foo<>(11); // B foo(11, 33); // C foo<int>(11, 33); // D foo(11, 22, 33); // E foo<int, int>(11, 22, 33); // F } I was pretty convinced that all the calls to foo were ambiguous, so I decided to test it with different …
Continue reading Curiosity #20160225A nullptr is a representation of the null pointer that implicitly converts into any pointer type, but not into an integral type. nullptr, and its type nullptr_t, have been standardised in C++11, but its introduction predates the standard by at least 15 years, since the idea is contained in Scott Meyer‘s book Effective C++, 2nd edition, published in 1996. Despite …
Continue reading Use nullptr if you can, 0 if you need, but please don’t use NULLI’m preparing some slides to explain how to write better code with C++11/14, and I wanted to start from the last thing I wrote about here, the use of keywords final and override. The scope of my previous post, albeit a bit cryptic, was to show how those keywords are context-sensitive, so you can also use final and override as type names, as …
Continue reading Final & Override again