Threads are an illusion - asynchronous programming with boost::asio
This talk was recorded during the LWG Meeting in Cologne:
Threads are an illusion - asynchronous programming with boost::asio
by Chris Kohlhoff
June 16-21, Sofia, Bulgaria
September 13-19, Aurora, CO, USA
October 25, Pavia, Italy
November 6-8, Berlin, Germany
November 16-21, Kona, HI, USA
By Meeting C++ | Mar 13, 2015 03:17 AM | Tags: performance intermediate efficiency c++11 boost basics
This talk was recorded during the LWG Meeting in Cologne:
Threads are an illusion - asynchronous programming with boost::asio
by Chris Kohlhoff
By Adrien Hamelin | Mar 11, 2015 01:54 PM | Tags: c++11 basics
Quick A: Wrong!
Recently on SO:
Return a local object rvalue reference,right or wrong?
I see once return a local object,the compiler will take the return value optimization.(RVO,NRVO).
The part of the Standard blessing the RVO goes on to say that if the conditions for the RVO are met, but compilers choose not to perform copy elision, the object being returned must be treated as an rvalue.
So we just write code like this:Widget makeWidget() { Widget w; … return w;//never use std::move(w); }I never see somebody write code like this:
Widget&& makeWidget() { Widget w; … return std::move(w); }I know that returns an lvalue reference of local object is always wrong. So, returns an rvalue reference of local object is also wrong?
By Blog Staff | Mar 7, 2015 06:06 PM | Tags: basics
Hot off kukuruku:
Secrets of the Conditional (ternary) Operator
by Alex Kulikov
(Note: Translation of the original Russian-language article here.)
From the article:
Every self-respecting C/C++ programmer knows what the ternary operator is, and most everyone used it at least once in their programs. But do you know all the secrets of the ternary operator? What potential dangers are associated with its use and what features, seemingly not related to its direct purpose, it has? This article gives you the opportunity to test your knowledge and maybe learn something new.
Let's start with a small test...
By Adrien Hamelin | Mar 6, 2015 11:21 AM | Tags: c++11 basics
Quick A: Because constexpr means can be evaluated at compile time, not that it will be. And it won’t be if the inputs aren’t compile-time constants.
Recently on SO:
I am confused about a constexpr function?
In C++ Primer, Fifth Edition, §6.5.2:
but another sentence in this chapter (page 239):A
constexpr
function is defined like any other function but must meet certain restrictions: The return type and the type of each parameter in must be a literal type (§2.4.4, p. 66), and the function body must contain exactly one return statementA constexpr function is permitted to return a value that is not a constant
// scale(arg) is a constant expression if arg is a constant expression constexpr size_t scale(size_t cnt) { return new_sz() * cnt; }Is it a contradictory summary? I am confused about it.
The return type ofscale
is literal type?
update: what's the difference between literal type and constant ?
By Adrien Hamelin | Mar 5, 2015 10:44 AM | Tags: c++11 basics
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 1Vector 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?
By Adrien Hamelin | Mar 5, 2015 10:40 AM | Tags: c++11 basics
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.
By Marcin Hoppe | Mar 5, 2015 01:56 AM | Tags: basics
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.
By Felix Petriconi | Feb 27, 2015 12:45 AM | Tags: boost basics
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.
By Adrien Hamelin | Feb 23, 2015 02:39 PM | Tags: c++11 basics
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...
By Adrien Hamelin | Feb 23, 2015 02:32 PM | Tags: c++11 basics
Here is a useful thing to know that appeared with C++11:
Non Static Data Members Initialization
by Bartlomiej Filipek
From the article:
My short summary for non static data members initialization from modern C++. A very useful feature. Should we use it or not?