Thursday, December 29, 2016

C++ tips, 2016 Week 51 (19-Dec - 25-Dec-2016)

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. The first rule about performance

Thursday, December 22, 2016

C++ tips, 2016 Week 50 (12-Dec - 18-Dec-2016)

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. Inherited constructors

Inherited constructors are used to reduce the boilerplate code in the case when the delivered class does not have new data members. In the case of this base class:

class Base 
{ 
public:
Base(int x, int y) : x_(x), y_(y) {} 
public: 
int x_; 
int y_; 
};

We can deliver from it:

class Derived : public Base 
{ 
using Base::Base; 
};

Thursday, December 15, 2016

C++ tips, 2016 Week 49 (5-Dec - 11-Dec-2016)

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. Capturing members by value

Imagine you want to return a lambda from an object that does some computations later but captures part of the state of that object:

class Boo { 
public: 
auto getValueMultiplier() { 
return [=](int multiplier) { 
return value * multiplier; 
}; 
} 
private: 
int value = 5; 
};

Thursday, December 8, 2016

C++ tips, 2016 Week 48 (28-Nov - 4-Dec-2016)

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::ratio

std::ratio is a class template for compile time rational arithmetics. Coupled with several alias templates for operations like std::ratio_add, std::ratio_multiply, etc you can do compile time arithmetics with rational numbers:

Thursday, December 1, 2016

C++ tips, 2016 Week 47 (21-Nov - 27-Nov-2016)

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. C++ is not going anywhere

That's the tip - it is a motivational one. I hear so many people announcing the death of C++ and how it is in decline and it is over. Even from within our community. Yet now there are more C++ developers than ever. Yes - other languages grow faster and the share of C++ is not growing but that is OK. It should be expected - we cant use C++ for everything. It does not make any sense.

The Committee is doing tremendous amount of work to add new features to the language without breaking 20+ years legacy code bases. Look at the current state (from Herb Sutter's Trip report: Fall 2016 ISO C++ standards meeting (Issaquah) ):