Archive for November, 2017

C++17: std::optional<>

Written by on November 21, 2017 in C++, Programming with 0 Comments
C++17: std::optional<>

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 […]

Continue Reading

C++17: std::variant<>

Written by on November 5, 2017 in C++, Programming with 0 Comments
C++17: std::variant<>

C++17 introduces a new type-safe union in the form of std::variant. At any time, it can store a single value from one of many types. We need to include <variant> to use this feature. Let us look at a simple example to get started: First, we define a variant object v1 to hold either an int […]

Continue Reading

Top