Quick Q: std::bind overload resolution
Quick A: the type of the function must be explicit.
Recently on SO:
std::bind overload resolution
You need a cast to disambiguate the overloaded function:
(int(A::*)(int,int))&A::operator()
June 8-13, Brno, Czechia
June 17-20, Folkestone, UK
September 12-18, Aurora, CO, USA
November 16-21, Búzios, Rio De Janeiro, Brazil
November 26-28, Berlin, Germany
By Adrien Hamelin | Jun 18, 2018 12:07 PM | Tags: advanced
Quick A: the type of the function must be explicit.
Recently on SO:
std::bind overload resolution
You need a cast to disambiguate the overloaded function:
(int(A::*)(int,int))&A::operator()
By Adrien Hamelin | Jun 6, 2018 12:06 PM | Tags: c++17 advanced
Really everything!
Everything You Need to Know About std::variant from C++17
by Bartlomiej Filipek
From the article:
Around the time C++17 was being standardized I saw magical terms like “discriminated union”, “type-safe union” or “sum type” floating around. Later it appeared to mean the same type: “variant”...
By Adrien Hamelin | May 28, 2018 01:08 PM | Tags: advanced
Quick A: const in a header implicitely means static.
Recently on SO:
use of constexpr in header file
constexprimplies const and const on global/namespace scope implies static (internal linkage), which means that every translation unit including this header gets its own copy of PI. The memory for that static is only going to be allocated if an address or reference to it is taken, and the address is going to be different in each translation unit.That implied static for const variables was introduced specifically to use const instead of #define in header files in C++ to define constants. Without static there would be multiple symbol definitions linker error if that header file is included in more than one translation unit which were linked together.
In C++17 you can also make it
inline, so that there is only ever a single copy of PI if an address or reference to it is taken (i.e. notstatic).inlinevariables were introduced in C++17 to allow for header-only libraries with non-const variable definitions in the header files.In other words, you should use
constexprfor your constants in header files, if possible, otherwiseconst. And if you require the address of that constant to be the same everywhere mark it asinline.
By Adrien Hamelin | May 23, 2018 01:00 PM | Tags: c++17 advanced
Take some time to clear your thoughts before reading!
Declarative Functional APIs – A.K.A. Abusing Lambda Parameters
by Philippe Groarke
From the article:
Functional APIs are a joy to work with. Not only do they help eliminate certain bug categories, but they tend to be very flexible and reusable. Today I present a technique that has emerged while I was simplifying some lambda based APIs. C++17 makes template meta-programming much more palatable, I dare not imagine what this would look like in C++11...
By Adrien Hamelin | May 23, 2018 12:54 PM | Tags: advanced
Do you have an opinion?
Should Span Be Regular?
by Barry Revzin
From the article:
In my last post, I talked about the concept of Westie types (yes, I am trying to make this happen), what Regular means, and which of them are Regular. I went through an explanation for why means for span is not Regular and potentially why it should be. After lots of resulting conversations with several people (thanks Zach Laine, Nicole Mazzuca, Eric Niebler, John Shaw, Tim Song), I thought it was necessary to write a follow up with more details and more argument...
By Adrien Hamelin | May 23, 2018 12:49 PM | Tags: advanced
Do you have that problem?
C++: On Using int*_t as Overload and Template Parameters
by No Bugs" Hare
From the article:
In C++, there is a concept of “two types being the same”. I am a Big Fan(tm) of this concept and find it very useful, but sometimes it starts causing trouble. Here is one such example – and a way I am using to deal with it...
By Adrien Hamelin | May 22, 2018 01:10 PM | Tags: c++17 advanced
Evolution of semantics.
Rvalues redefined
by Andrzej Krzemieński
From the article:
In this post we will explore what I consider the most significant language change in C++17. I call it the most significant because it changes the way you design your resource-managing types and how you think about initialization. It is often called “guaranteed copy elision”, but I will not use that name (except for this single time) because it does not reflect what this feature is. C++ has completely changed the meaning of rvalue (actually, prvalue)...
By Adrien Hamelin | May 21, 2018 12:17 PM | Tags: advanced
The next part.
How to Make SFINAE Pretty – Part 2: the Hidden Beauty of SFINAE
by Jonathan Boccara
From the article:
As we’ve seen in How to Make SFINAE Pretty – Part 1: What SFINAE Brings to Code, SFINAE in code is as pretty as a windmill in a field. That is, not very pretty.
But like a windmill, it’s useful. SFINAE helps deactivate a piece of template code depending on a condition, and that can be very convenient...
By Adrien Hamelin | May 21, 2018 12:16 PM | Tags: advanced
New series!
How to Make SFINAE Pretty – Part 1: What SFINAE Brings to Code
by Jonathan Boccara
From the article:
SFINAE is a bit like a windmill. It sits as a wart in the middle of an interface, BUT it’s useful to create elaborate static polymorphism, in particular before C++17 and if constexpr, and even in some use cases in C++17.
I thought we had to live with this tradeoff, until I watched a talk from Stephen Dewhurst at CppCon. In this inspring talk, Stephen shows how to turn SFINAE around to make it very expressive in an interface. Watching this talk changed my way of coding template interfaces...
By Adrien Hamelin | May 18, 2018 11:19 AM | Tags: community advanced
What do you think?
Default-constructibility is overrated
by Arthur O’Dwyer
From the article:
The Ranges Technical Specification includes very many concept definitions (based on the Concepts TS), including for example Integral and Predicate. It also provides a concept named Regular which implements a variation on the “Regular” concept described by Alexander Stepanov in his paper '’Fundamentals of Generic Programming’’ (1998)...