Wednesday, October 26, 2016

C++ tips, 2016 Week 42 (17-Oct - 23-Oct-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. Using parameter pack to write one_of
This one is from Jason Turner (here and here). Instead of writing:
if (thing.x == 1 || thing.x == 2 || thing.x == 3)
you can write:

template<typename U, typename ... T> 
bool one_of(U&& u, T && ... t) 
{
  return ( (u == t) || ...  ); 
}

Tuesday, October 25, 2016

Starting C++ weekly posts

I volunteered to make daily C++ tips for the people development program at my work. And I decided that if I'm going to make them anyway it will be even better if I wrap them in a weekly post.

Because even after all this years in C++ there is still much to learn ( I cant escape the feeling that I'm complete newbie ) the tips will be part what I currently read from the news feed, part of what I think is important and part something-I-just-discovered-that-I-must-have-known-years-ago.  My definition of tip is a small piece of knowledge that can be useful in day-to-day programming or it can broaden your perspective and give you directions to more bigger knowledge. That is why I'll try to keep the scope as broad as possible (and because I'm the encyclopedist type of person - my brain easily collects random pieces of knowledge but some times not the things I want or have to remember). Wish me luck and discipline to keep this going.

Full list of all C++ weekly tips posts: