Compile c++14-code with g++

For gcc 4.8.4 you need to use -std=c++1y in later versions, looks like starting with 5.2 you can use -std=c++14. If we look at the gcc online documents we can find the manuals for each version of gcc and we can see by going to Dialect options for 4.9.3 under the GCC 4.9.3 manual it … Read more

error::make_unique is not a member of ‘std’

make_unique is an upcoming C++14 feature and thus might not be available on your compiler, even if it is C++11 compliant. You can however easily roll your own implementation: template<typename T, typename… Args> std::unique_ptr<T> make_unique(Args&&… args) { return std::unique_ptr<T>(new T(std::forward<Args>(args)…)); } (FYI, here is the final version of make_unique that was voted into C++14. This … Read more

Throw in constexpr function

clang is correct, note the HEAD revision of gcc accepts also accepts this code. This is a well-formed constexpr function, as long as there is value for the argument(s) that allows the function to be evaluated as a core constant expression. In your case 1 is such a value. This is covered in the draft … Read more

Why was the space character not chosen for C++14 digit separators?

There is a previous paper, n3499, which tell us that although Bjarne himself suggested spaces as separators: While this approach is consistent with one common typeographic style, it suffers from some compatibility problems. It does not match the syntax for a pp-number, and would minimally require extending that syntax. More importantly, there would be some … Read more

details of std::make_index_sequence and std::index_sequence

I see sample code around there, but I really want a dumbed down step by step explanation of how an index_sequence is coded and the meta programming principal in question for each stage. What you ask isn’t exactly trivial to explain… Well… std::index_sequence itself is very simple: is defined as follows template<std::size_t… Ints> using index_sequence … Read more

How to make std::make_unique a friend of my class

make_unique perfect forwards the arguments you pass to it; in your example you’re passing an lvalue (x) to the function, so it’ll deduce the argument type as int&. Your friend function declaration needs to be friend std::unique_ptr<A> std::make_unique<A>(T&); Similarly, if you were to move(x) within CreateA, the friend declaration would need to be friend std::unique_ptr<A> … Read more

Calling initializer_list constructor via make_unique/make_shared

std::make_unique is a function template which deduces the argument types which are passed to the object constructor. Unfortunately, braced lists are not deducible (with an exception for auto declarations), and so you cannot instantiate the function template when that missing parameter type. You can either not use std::make_unique, but please don’t go that route – … Read more

Which headers in the C++ standard library are guaranteed to include another header?

This answer ignores C headers – both the <meow.h> and <cmeow> ones. Of the C++ library headers (all references are to N4659): <initializer_list> is guaranteed to be included by: <utility> (§23.2.1 [utility.syn]) <string> (§24.3.1 [string.syn]) <array> (§26.3.2 [array.syn]) <deque> (§26.3.3 [deque.syn]) <forward_list> (§26.3.4 [forward_list.syn]) <list> (§26.3.5 [list.syn]) <vector> (§26.3.6 [vector.syn]) <map> (§26.4.2 [associative.map.syn]) <set> (§26.4.3 … Read more