Author: Anders Schau Knatten
-
Visiting CppCast
I recently had the pleasure of being the guest of the week on CppCast! I chatted with Phil and Timur about CppQuiz.org‘s recent move to C++23, my book C++ Brain Teasers, and a bit about safety, the future of C++, and more. You can listen to the …
-
How Symbols Work and Why We Need Them
My talk “How Symbols Work and Why We Need Them” from C++ on Sea is finally out on YouTube! Knowing how symbols work and how they are used can be very useful. Not only when solving linker errors but also when consuming or creating libraries, and even when creating executables. But most importantly, it is … Continue reading How Symbols Work and Why We Need Them
-
CppQuiz.org is now on C++23
If you’re not familiar with https://cppquiz.org, it is, as its name suggests, a C++ quiz site. Each quiz is a full C++ program, and your task is to figure out what the output is. But the real value often lies in the explanation, which goes into detail about why the answer is what it is. … Continue reading CppQuiz.org is now on C++23
-
C++ Brain Teasers Book Launch September 10 (live+streaming)
On September 10 there will be a book launch event for my book C++ Brain Teasers organized by Oslo C++ Users Group at NDC TechTown in Kongsberg. The event starts with food and mingling at 18:00, and the book launch starts at 18:30. Check out the event at Meetup.com for more details. The event will … Continue reading C++ Brain Teasers Book Launch September 10 (live+streaming)
-
I wrote a C++ book!
I’m very proud to announce that my first book just got released on The Pragmatic Programmers! The book is called “C++ Brain Teasers“, and is part of their Brain Teasers series. The book consists of 25 short C++ programs, and the point is to guess what the output is, and why the language works like … Continue reading I wrote a C++ book!
-
Help get CppQuiz to C++23 and win a book!
CppQuiz.org is currently using C++ 17 for explanations and needs porting to C++ 23. I’d really appreciate your help! As a thank you, three contributors will get a copy of my upcoming book C++ Brain Teasers. How do I help? All the questions from the site have been exported to https://github.com/knatten/cppquiz23. Full instructions are in … Continue reading Help get CppQuiz to C++23 and win a book!
-
References don’t have top-level cv-qualifiers
Sometimes when reading about C++, for instance about template argument deduction, the term “top-level cv-qualifiers” comes up. I just spent an unreasonable amount of time being puzzled by something because I didn’t understand that references don’t have top-level cv-qualifiers. This post will hopefully help the next person (hi, next-year Anders) not make the same mistake. … Continue reading References don’t have top-level cv-qualifiers
-
Why we probably shouldn’t have constexpr conditional operator
The idea I had a great idea. We have constexpr if, but no constexpr conditional operator. Time for a proposal? Since we can do stuff like this: Wouldn’t it be cool if we could also do My motivation was that I had a std::variant visitor that was identical for all types except one. So instead … Continue reading Why we probably shouldn’t have constexpr conditional operator
-
Microsoft C++ versions explained
Microsoft has five different version numbers to think about when it comes to C++. Here’s an attempt to explain what they all mean. Visual Studio versions What most people will see first is the Visual Studio release year. You’ll download Visual Studio 2022, Visual Studio 2019 etc. These however also have a more normal major.minor … Continue reading Microsoft C++ versions explained
-
The difference between no move constructor and a deleted move constructor
It’s easy to think that deleting the move constructor means removing it. So if you do MyClass(MyClass&&) = delete , you make sure it doesn’t get a move constructor. This is however not technically correct. It might seem like a nitpick, but it actually gives you a less useful mental model of what’s going on. … Continue reading The difference between no move constructor and a deleted move constructor
-
No-one knows the type of char + char
Quick quiz! Given the following: Which overload gets called by the following? Alternatives: f(unsigned int) f(int) f(char) No-one knows the type of char + char If you answered 4), congratulations! And if you answered 2), maybe you tried the code on your own computer? Most people will get f(int) when they try this code, but … Continue reading No-one knows the type of char + char
-
static_assert in templates
Quiz time! Which of the following programs can you expect to not compile? For bonus points, which are required by the C++ standard to not compile? Program 1 Program 2 Program 3 In case you’re not familiar with static_assert, it takes a constant boolean expression, and if it evaluates to false, you get a compilation … Continue reading static_assert in templates
-
+!!””
In this Tweet, @willkirkby posts: +!!”” that evaluates as 1 in C/C++, but no, JavaScript is the weird language C++ is indeed weird, or at least it’s very weakly typed. Let’s go through all the details of what’s going on here: Summary: Starting from the right, “” is a string literal, which gets converted to … Continue reading +!!””
-
Why you can’t list-initialize containers of non-copyable types
Have you ever wondered why you can’t list-initialize containers of non-copyable types? This is for instance not possible: If you ever wondered, or if you now are, read on! List-initialization Since C++11, you’re probably used to intitalizing containers like this: This of course also works with user defined types. Let’s say you have a class … Continue reading Why you can’t list-initialize containers of non-copyable types