Which parts of the C++14 Standard Library could be and which parts will be made constexpr?

which parts of the Standard Library will now be marked constexpr? From the draft that I’ve looked at for C++14, N3690, the following will be changed to constexpr thus far (In comparison with the C++11 standard)†: std::error_category‘s default constructor std::forward std::move std::move_if_noexcept All of std::pair‘s operator comparisons std::get for std::pair and std::tuple. std::make_tuple All of … Read more

Why can a braced-init-list not be used as an expression in a conditional operator?

Well, here’s what a note in the C++11 standard, [dcl.init.list] p1 says: List-initialization can be used as the initializer in a variable definition ([dcl.init]) as the initializer in a new expression ([expr.new]) in a return statement ([stmt.return]) as a function argument ([expr.call]) as a subscript ([expr.sub]) as an argument to a constructor invocation ([dcl.init], [expr.type.conv]) … Read more

Library design: allow user to decide between “header-only” and dynamically linked?

Preliminary note: I am assuming a Windows environment, but this should be easily transferable to other environments. Your library has to be prepared for four situations: Used as header-only library Used as static library Used as dynamic library (functions are imported) Built as dynamic library (functions are exported) So let’s make up four preprocessor defines … Read more

Default move constructor vs. Default copy constructor vs. Default assignment operator

I believe backwards compatibility plays a big part here. If the user defines any of the “Rule of three” functions (copy ctor, copy assignment op, dtor), it can be assumed the class does some internal resource management. Implicitly defining a move constructor could suddenly make the class invalid when compiled under C++11. Consider this example: … Read more

Constexpr is not allowed in declaration of friend template specialization?

GCC is wrong here. All references are to N4431, the latest C++ WD. [tl;dr: There’s a difference between a function being inline (or more precisely, being an inline function, as defined in 7.1.2/2) and being declared with the inline specifier. The constexpr specifier makes a function inline, but isn’t an inline specifier.] Specifiers are described … Read more

Ternary operator + C++11 constructor from initializer_list [duplicate]

Standard writes in 8.5.4.1: List-initialization Note: List-initialization can be used as the initializer in a variable definition (8.5) as the initializer in a new expression (5.3.4) in a return statement (6.6.3) as a function argument (5.2.2) as a subscript (5.2.1) as an argument to a constructor invocation (8.5, 5.2.3) as an initializer for a non-static … Read more

OpenMP vs C++11 threads

OpenMP thread-pools for its Pragmas (also here and here). Spinning up and tearing down threads is expensive. OpenMP avoids this overhead, so all it’s doing is the actual work and the minimal shared-memory shuttling of the execution state. In your Threads code you are spinning up and tearing down a new set of 16 threads … Read more

How to deal with static storage duration warnings?

One way to defer initialization of global variables such as the ones you are using is to wrap them in get-functions. std::default_random_engine& getEngine() { // Initialized upon first call to the function. static std::default_random_engine engine(static_cast<unsigned int>(time(nullptr))); return engine; } std::uniform_int_distribution<unsigned int>& getRandomInt() { // Initialized upon first call to the function. static std::uniform_int_distribution<unsigned int> randomInt(1, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)