Is it a conforming compiler extension to treat non-constexpr standard library functions as constexpr?

TL;DR In C++14 this is explicitly not allowed, although in 2011 it appeared like this case would be explicitly allowed. It is unclear if for C++11 this fell under the as-if rule, I don’t believe it does since it alters observable behavior but that point was not clarified in the issue I reference below. Details … Read more

Why use std::bind over lambdas in C++14?

Scott Meyers gave a talk about this. This is what I remember: In C++14 there is nothing useful bind can do that can’t also be done with lambdas. In C++11 however there are some things that can’t be done with lambdas: You can’t move the variables while capturing when creating the lambdas. Variables are always … Read more

Differences between std::make_unique and std::unique_ptr with new

The motivation behind make_unique is primarily two-fold: make_unique is safe for creating temporaries, whereas with explicit use of new you have to remember the rule about not using unnamed temporaries. foo(make_unique<T>(), make_unique<U>()); // exception safe foo(unique_ptr<T>(new T()), unique_ptr<U>(new U())); // unsafe* The addition of make_unique finally means we can tell people to ‘never’ use new … Read more

How to create an std::function from a move-capturing lambda expression?

template<class F> function(F f); template <class F, class A> function(allocator_arg_t, const A& a, F f); Requires: F shall be CopyConstructible. f shall be Callable for argument types ArgTypes and return type R. The copy constructor and destructor of A shall not throw exceptions. ยง20.9.11.2.1 [func.wrap.func.con] Note that operator = is defined in terms of this … Read more

What are transparent comparators?

What problem does this solve, See Dietmar’s answer and remyabel’s answer. and does this change how standard containers work? No, not by default. The new member function template overloads of find etc. allow you to use a type that is comparable with the container’s key, instead of using the key type itself. See N3465 by … Read more

How does `void_t` work

1. Primary Class Template When you write has_member<A>::value, the compiler looks up the name has_member and finds the primary class template, that is, this declaration: template< class , class = void > struct has_member; (In the OP, that’s written as a definition.) The template argument list <A> is compared to the template parameter list of … Read more

Implementation C++14 make_integer_sequence

Here’s a log N implementation that doesn’t even need an increased max-depth for template instantiations and compiles pretty fast: // using aliases for cleaner syntax template<class T> using Invoke = typename T::type; template<unsigned…> struct seq{ using type = seq; }; template<class S1, class S2> struct concat; template<unsigned… I1, unsigned… I2> struct concat<seq<I1…>, seq<I2…>> : seq<I1…, … Read more

How to implement classic sorting algorithms in modern C++?

Algorithmic building blocks We begin by assembling the algorithmic building blocks from the Standard Library: #include <algorithm> // min_element, iter_swap, // upper_bound, rotate, // partition, // inplace_merge, // make_heap, sort_heap, push_heap, pop_heap, // is_heap, is_sorted #include <cassert> // assert #include <functional> // less #include <iterator> // distance, begin, end, next the iterator tools such as … Read more

Has C++ standard changed with respect to the use of indeterminate values and undefined behavior in C++14?

Yes, this change was driven by changes in the language which makes it undefined behavior if an indeterminate value is produced by an evaluation but with some exceptions for unsigned narrow characters. Defect report 1787 whose proposed text can be found in N39141 was recently accepted in 2014 and is incorporated in the latest working … Read more