Weeky C++ 11- Using std::initializer_list as parameter

Modern C++ (3): Uniform Initialization, override/final, default/delete, constexpr, etc.

Let assume that, we want to have a set of parameters of the same type in any method or constructor. We don’t want to use std::vector and similar containers (they don’t look so good 🙂 and we want to do this in a modern way. How are we going to do? Let’s see it 🙂


Our goal is to add points to this class (let’s assume that they are two-dimensional for now), in an easy way. Normally, you can add them individually or via a vector or array. Now let’s look at how we do this using std::initializer_list and how many different ways.

Yes friends, I think the code above shows a lot of examples in the sense of the use of std::initializer_list. This kind of structures, I think, make the code really more readable and simple. That’s why I suggest you to start using it immediately.

I’m yazilimperver, see you in my next post. Happy codings 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.