Partners: KDAB Whole Tomato Software CppDepend

18 June 2018

Everything You Need to Know About std::any from C++17

Using std::any in C++17

With std::optional you can represent some Type or nothing. With std::variant you can wrap several variants into one entity. And C++17 gives us one more wrapper type: std::any that can hold anything in a type-safe way.

11 June 2018

A Wall of Your std::optional Examples

std::optional contest

Two weeks ago I asked you for help: I wanted to build a wall of examples of std::optional. I’m very grateful that a lot of you responded and I could move forward with the plan!

You’re amazing!

Let’s dive in the examples my readers have sent me!

04 June 2018

Everything You Need to Know About std::variant from C++17

Using std::variant in C++17

Around the time C++17 was being standardized I saw magical terms like “discriminated union”, “type-safe union” or “sum type” floating around. Later it appeared to mean the same type: “variant”.

Let’s see how this brand new std::variant from C++17 works and where it might be useful.

28 May 2018

Show me your code: std::optional

std::optional contest

Show me your code!

I’d like to run a little experiment.

Let’s build a wall of examples of std::optional!

21 May 2018

Error Handling and std::optional

Error handling and std::optional

In my last two posts in the C++17 STL series, I covered how to use std::optional. This wrapper type (also called “vocabulary type”) is handy when you’d like to express that something is ‘nullable’ and might be ‘empty’. For example, you can return std::nullopt to indicate that the code generated an error… but it this the best choice?

14 May 2018

C++ Templates - The Complete Guide 2nd Book Review

C++ Templates - The Complete Guide 2nd Book review

A few months ago I received a quite massive mail package with something that was looking like a brand new C++ book :)

My initial plan was to review it quickly, maybe in one month. But I failed, as learning C++ templates is not that easy :) I needed much more time.

Time passed by and now I am ready for the review, so here you have it :) See my thoughts about the fantastic book on C++ templates, “the templates book” as many people call it.

07 May 2018

Using C++17 std::optional

Using std::optional, C++

Let’s take a pair of two types <YourType, bool> - what can you do with such composition?

In this article, I’ll describe std:optional - a new helper type added in C++17. It’s a wrapper for your type and a flag that indicates if the value is initialized or not. Let’s see where it can be useful and how you can use it.

23 April 2018

Refactoring with C++17 std::optional

Refactoring with C++17 std::optional

There are many situations where you need to express that something is “optional” - an object that might contain a value or not. You have several options to implement such case, but with C++17 there’s probably the most helpful way: std::optional.

For today I’ve prepared one refactoring case where you can learn how to apply this new C++17 feature.

09 April 2018

Productive C++ Developer, my recent talk

C++ Goodies and tools

A few weeks ago I gave another talk at my local C++ user group. We discussed recent “goodies” from C++ and tools that can increase productivity.

01 April 2018

Deprecating Raw Pointers in C++20

Raw pointers in C++

The C++ Standard moves at a fast pace. Probably, not all developers caught up with C++11/14 yet and recently we got C++17. Now it’ time to prepare C++20!
A few weeks ago The C++ Committee had an official ISO meeting in Jacksonville, FL (12-17 March 2018) where they worked hard on the new specification.

Besides many significant things that were discussed at the meeting like modules, concepts, ranges, The C++ Committee accepted one hugely anticipated feature: deprecation of raw pointers!

26 March 2018

The C++ Standard Library book - overview & giveaway

Let’s have a quick overview of another book related to Modern C++ and The Standard Library. This time I picked Rainer Grimm’s book the author of the modernescpp blog.

Read more if you’d like to win C++ book bundle! :)

12 March 2018

Simplify code with 'if constexpr' in C++17

Simplify your code with if constexpr in C++17

Before C++17 we had a few, quite ugly looking, ways to write static if (if that works at compile time) in C++: you could use tag dispatching or SFINAE (for example via std::enable_if). Fortunately, that’s changed, and we can now take benefit of if constexpr!

Let’s see how we can use it and replace some std::enable_if code.

26 February 2018

What happens to your static variables at the start of the program?

Static Variables in C++

Saying that C++ has simple rules for variables initialization is probably quite risky :) For example, you can read Initialization in C++ is Bonkers : r/cpp to see a vibrant discussion about this topic.

But let’s try with just a small part of variables: static variables.
How are they initialized? What happens before main()(*) ?

12 February 2018

Static Variables Initialization in a Static Library, Example

C++ static variables initialization and linker, one example

This post is motivated by one important comment from my last article about factories and self-registering types:

(me) So the compiler won’t optimize such variable.

Yet, unfortunately, the linker will happily ignore it if linking from a static library.

So… what’s the problem with the linker?

© 2017, Bartlomiej Filipek, Blogger platform
Any opinions expressed herein are in no way representative of those of my employers.
This site contains ads or referral links, which provide me with a commission. Thank you for your understanding.