Saturday, February 25, 2017

C++ User Group Sofia first year

Some time in November 2015 we decided that it is a shame that we do not have a C++ User Group in Sofia, Bulgaria, and we decided that instead of waiting to just make it. This is a retro and an overview of what happened in our first year. I hope you find it helpful and inspirational.

A year or two earlier I began to realize that I'm a dark matter developer and I started to read more articles, created dedicated dev twitter account, started listening to podcasts (thank you, CppCast!) - it was kind of waking up experience. When you plug into the C++ news stream you begin to realize that our community is currently flourishing and expanding. As the community grows there is need for more face to face communication -  nothing replaces face to face communication. Probably realizing that Jens Weller, a.k.a. Meeting C++, started to encourage and help creating C++ User Groups.

Monday, February 20, 2017

C++ tips, 2017 Week 6 (6-Feb - 12-Feb-2017)

This is part of my weekly C++ posts based on the daily C++ tips I make at my work. I strongly recommend this practice. If you dont have it in your company start it. 
List of all weekly posts can be found here.

1. Trailing return type

In C++11 we got trailing return type. That is we can write the return type at the end:


reason for this was lambdas with multiple return statements and function templates that that have return type dependent on the input parameter types:


however from C++14 we have Generalized return type deduction and now in most of the cases you can omit writing the trailing return type and just use auto.

Friday, February 10, 2017

C++ tips, 2017 Week 5 (30-Jan - 5-Feb-2017)

This is part of my weekly C++ posts based on the daily C++ tips I make at my work. I strongly recommend this practice. If you dont have it in your company start it. 
List of all weekly posts can be found here.

1. std::size, data, empty

From C++17 we are getting the free functions std::size, std::data, std::empty. They are similar to the free functions std::begin and std::end and if used with standard container just call the corresponding member function and work for C-style arrays if it makes sense. Possible std::size implementation for C-style arrays (container one just returns .size()):

(lets try GitHub Gist because Blogger formatting is driving me nuts)

Thursday, February 2, 2017

C++ tips, 2017 Week 4 (23-Jan - 29-Jan-2017)

This is part of my weekly C++ posts based on the daily C++ tips I make at my work. I strongly recommend this practice. If you dont have it in your company start it. 
List of all weekly posts can be found here.


1. .front() and .back()

The sequence containers from STL have these two functions for accessing the first or the last element of the container (or an analogue like std::priority_queue::top). They do not return iterator but a reference to the object in the vector.

We've all seen code like this:
std::vector<SomeElement> elements;

// later

SomeElement element;
// some calculations and initializations involving the element
// possibly passing it around by reference
elements.push_back(element);
//or
elements.emplace_back(std::move(element));
This is where .back() comes handy - instead of creating local variable and than inserting into the container sometimes it is better to insert it first and than work directly with the inserted object getting access to it by using back/front/top/etc:
elements.emplace_back();
auto& element = elements.back();

// same calculations and initializations involving the element
// possibly passing it around by reference
This is applicable in the simpler cases and there is no need to involve copy/move semantics.