Tag: C++17

Calling a function (or function object) dynamically, through a pointer known at runtime, is a common programming scenario. Almost all languages support this use case. Lisp, for example, has apply and funcall. When using apply, you can see that the arguments are passed via a separate list object. With funcall, however, the arguments are passed […]
Title: The Modern C++ Challenge Author: Marius Bancilla Publisher: Packt Publishing Year: May 2018 This week I have been going through a new book titled The Modern C++ Challenge written by Marius Bancilla. The book is a collection of programming problems (along with suggested solutions) targeting C++ . The title of the book is a […]

constexpr if is another nice little feature in C++17, which significantly simplifies the way we code, especially in the context of templates. In this article, I will briefly talk about this feature and look at some examples. constexpr if is a variant of the standard if statement we have had all along. The primary difference […]

In the previous two posts, I talked about std::variant<> and std::optional<>. Today, I want to take up std::any for discussion. The type any (implemented by the class any) allows a variable to hold a single value of any type. More interestingly, the type of the value held by a variable of type any can even […]

Suppose we want to write a function that returns a value, but with the possibility that the computation might fail. This failure can be represented as an exception, or as a return value that unamibiguously denotes failure (for example, -1). Throwing an exception is a strong form of failure and might not be appropriate in […]

C++17 enhances if and switch statements with the ability to define variables whose life-time is limited to the corresponding scope. This is in keeping with the general guideline that variables should have a tight scope, i.e., should be defined as close to the point of use as possible and should not live beyond where they […]
Recent Comments