basics

Quick Q: How to write variadic template constructor?

Quick A: use an std::initializer_list.

Recently on SO:

Writting variadic template constructor

Recently I asked this question but now I would like to expand it. I wrote the following class:

template <class T>
class X{
public:
    vector<T> v;
    template <class T>
    X(T n) {
        v.push_back(n);
    }
    template <class T, class... T2>
    X(T n, T2... rest) {
        v.push_back(n);
        X(rest...);
    }
};

When creating and object using

X<int> obj(1, 2, 3);  // obj.v containts only 1

Vector only contains the first value, but not others. I've checked and saw that constructor is called 3 times, so I'm probably creating temp objects and filling their vectors with the rest of the arguments. How do I solve this problem?

Quick Q:How to modify a tuple in a vector of tuples c++?

Quick A: Capture the tuple by reference.

Recently on SO:

Modifying a tuple in a vector of tuples c++

I have a vector of tuples vector<tuple<int,int>> vector; and I want to modify one of the tuples it contains.

for (std::tuple<int, int> tup : std::vector)
{
    if (get<0>(tup) == k)
    {
        /* change get<1>(tup) to a new value
         * and have that change shown in the vector
         */
    }
}

I am unsure how to change the value of the tuple and have the change be reflected in the vector. I have tried using

get<1>(tup) = v;

but that doesn't change the value of the tuple that is in the vector. How can I do this? Thanks.

How to write a standard-like algorithm -- Indi

Explicit C++ has posted a nice tutorial on how to implement an algorithm in C++.

How to write a standard-like algorithm

by Indi

from the article:

Writing a standard-like algorithm should be one of the key parts of a modern C++ beginner’s course outline. This post will be a whirlwind guide through the steps toward creating a standard-like algorithm. The focus is not on the algorithm itself, but on the process of creating one.

Operator Overloading – Introduction to Boost.Operators -- Arne Metz

Arne Mertz goes into the details of using boost operators.

Operator Overloading – Introduction to Boost.Operators, Part 1

Operator Overloading – Introduction to Boost.Operators, Part 2

by Arne Mertz

From the articles:

In my first two posts about operator overloading I have written about the basics and common practice. This post shows some lessons from the common practice post on a concrete example and then introduces to Boost.Operators, a library that conveniently reduces the boilerplate involved when overloading multiple operators for a class.

Operators Travel in Packs

If we look at the list of operators, we see that there are about 50 of them, and many of them can be overloaded in different ways. Even if we restrict ourselves to a few operations that make sense for a given class, then one of those operations often brings two or more operators.

 

Type Deduction and Braced Initializers--Arne Mertz

If you are confused about the topic, read this article:

Type Deduction and Braced Initializers

by Arne Mertz

From the article:

I just finished watching a talk from CppCon 2014 by Scott Meyers: Type Deduction and Why You Care. All in all it was a very interesting and entertaining talk, and I learned a thing or two, especially about the combination of type deduction and braced initializers. Since this blog is about simplifying the use of C++, I want to have a short look at that special combination and derive a rule of thumb from it...

Boost libraries are now supported in biicode

First step to a complete integration of the C++ deps manager biicode with the most popular set of C++ libs: Boost libraries.

Boost libraries are now supported in biicode

by Manu Sánchez

From the news:

At biicode we have been working hard to simplify the process of making Boost available for any C++ programmer with just an include. But this is only the start, the project has been released as open source to allow everyone contribute and help.

CppCon 2014 Make Simple Tasks Simple!--Bjarne Stroustrup

While we wait for CppCon 2015 in September, we’re featuring videos of some of the 100+ talks from CppCon 2014. Here is today’s feature:

Elevate Your Code to Modern C++11 with Automated Tooling

by Bjarne Stroustrup

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

C++ faces two challenges: Helping programmers address the most demanding tasks in terms of performance, scale, and dependability. It must also help programmers be productive writing ordinary maintainable code. There is much more "ordinary code" than there is performance-critical code. Thus, C++ must make simple tasks simple while not getting in the way of tuning software for the last byte and last cycle where that's necessary. This talk focuses on what C++11 and C++14 offers to simplify programming: auto, range-for loops, move semantics, futures, concepts, and more. However, the focus is not primarily on language features: the key is programming: how can we write better, more readable, efficient, and more maintainable code? If you think that the essence of C++ is clever pointer manipulation and huge class hierarchies you may be in for a few surprises.

cppcast episode 1: Jon Kalb loves the C++ Community

cppcast.PNGThis is the first episode of cppcast, the only podcast by C++ developers for C++ developers. In this first episode host Rob Irving interviews Jon Kalb about the state of the C++ Community.

cppcast episode 1: Jon Kalb loves the C++ Community

by Rob Irving

About the interviewee:

Jon has been writing C++ for two and half decades, does onsite C++ training, and works on the Amazon search engine for A9.com. He chairs the CppCon and C++Now conferences. He also programs the C++ Track for the Silicon Valley Code Camp and serves as chair of the Boost Libraries Steering Committee.