c++14

Compilation of C++14 in qtcreator

我怕爱的太早我们不能终老 提交于 2019-12-07 01:02:51
问题 I have a qt project containing parts in C++14 . Recently, I changed my ubuntu distro. Now I have 16.04 LTS and I installed Qt creator 4.02 (built on jun 13). In order to enable C++14 compilation, I put in the project file: QMAKE_CXXFLAGS += -std=c++14 However, when building project, the IDE generates the following command: g++ -c -pipe -std=c++14 -g -O0 -g -std=gnu++11 -Wall -W -D_REENTRANT ... As seen, the generated makefile puts the flag -std=gnu++11 which overrides the flag for C++14 .

Perfect forwarding in a lambda?

做~自己de王妃 提交于 2019-12-07 00:48:37
问题 With a function, one can write: template <class T> void f(T&& x) {myfunction(std::forward<T>(x));} but with a lambda, we don't have T : auto f = [](auto&& x){myfunction(std::forward</*?*/>(x));} How to do perfect-forwarding in a lambda? Does decltype(x) work as the type in std::forward ? 回答1: The canonical way to forward a lambda argument that was bound to a forwarding reference is indeed with decltype : auto f = [](auto&& x){ myfunction(std::forward<decltype(x)>(x)); } // ^^^^^^^^^^^ 回答2: My

Casting a char array to an object pointer - is this UB?

我的未来我决定 提交于 2019-12-07 00:22:26
问题 I recently saw a class like this that was used to construct objects "on-demand" without having to use dynamic memory allocation for various reasons. #include <cassert> template<typename T> class StaticObject { public: StaticObject() : constructed_(false) { } ~StaticObject() { if (constructed_) ((T*)object_)->~T(); } void construct() { assert(!constructed_); new ((T*)object_) T; constructed_ = true; } T& operator*() { assert(constructed_); return *((T*)object_); } const T& operator*() const {

Unpacking a typelist

狂风中的少年 提交于 2019-12-07 00:08:07
问题 Lets say I have a function that takes just a type template parameter, I cannot change it's definition/implementation. template < typename T > void do_it(); Now I have a typelist defined a usual way, can't change it either: template< typename ...Ts > struct typelist; I want to implement a function that takes a typelist, and runs do_it() on every type: template< typename List > void do_them(); The only solution I found up 'till now is: template< typename T > void do_them_impl() { do_it<T>(); }

Custom allocators vs. promises and packaged tasks

大憨熊 提交于 2019-12-07 00:04:24
问题 Are the allocator-taking constructors of standard promise / packaged_task supposed to use the allocator for just the state object itself, or should this be guaranteed for all (internal) related objects? [futures.promise]: "...allocate memory for the shared state" [futures.task.members]: "...allocate memory needed to store the internal data structures" In particular, are the below bugs or features? *MSVC 2013.4, Boost 1.57, short_alloc.h by Howard Hinnant Example 1 #define BOOST_THREAD_VERSION

Simple constexpr LookUpTable in C++14

情到浓时终转凉″ 提交于 2019-12-06 23:01:21
问题 I am trying to make a simple LookUpTable based on an array of integers, where the idea is to have it calculated at compile time . Trying to make it possible to use it for any other future tables of various integer types I might have, I need it as a template . So I have a LookUpTable.h #ifndef LOOKUPTABLE_H #define LOOKUPTABLE_H #include <stdexcept> // out_of_range template <typename T, std::size_t NUMBER_OF_ELEMENTS> class LookUpTableIndexed { private: //constexpr static std::size_t NUMBER_OF

How can I detect whether a template argument is a noexcept function?

丶灬走出姿态 提交于 2019-12-06 20:17:13
问题 I have function to generate a lambda that acts as a wrapper to a function I can invoke later: template <typename F, typename... FArgs> auto make_lambda( F&& f, FArgs&&... f_args ) { return [&] () -> std::result_of_t<F( FArgs... )> { return std::forward<F>( f )( std::forward<FArgs>( f_args )... ); }; } I'd like to make the returned lambda noexcept when argument f is noexcept , so my function's return would look like this: return [&] () noexcept( is_noexcept<decltype( f )>::value ) -> std:

Conversion from integral constant expression to null-pointer

有些话、适合烂在心里 提交于 2019-12-06 19:26:51
问题 Consider following code: #include <memory> void f( std::shared_ptr<int> ) {} int main() { f( 0 ); // compiles fine in gcc and clang f( 1 - 1 ); // compiles fine in gcc, fails in clang constexpr int i = 0; f( i ); // fails to compile in gcc and clang f( i - 0 ); // compiles fine in gcc, fails in clang } why only f( i ) fails to compile, though i should be evaluated as compile time constant with value 0? PS checked with g++ v 5.1.0, it accepts all variants except f(i); in both c++11 and c++14

Dereferencing a function with default arguments - C++14 vs C++11

大城市里の小女人 提交于 2019-12-06 18:33:24
问题 Following code can't be compiled with g++ version 5.4.0 with option -std=c++1y : void f(int=0) ; int main() { f(); // ok (*f)(2);// ok (*f)();// ok c++11; error with c++14: too few arguments to function return 0; } The function declared to have default argument, so what is wrong here? thanks for help. And why does g++ -c -std=c++11 compile? 回答1: Accepting (*f)() as valid is a GCC bug. The letter of the standard indicates that using a function name with unary * should cause the function name

make_unique arrays, original proposal vs. final

我只是一个虾纸丫 提交于 2019-12-06 17:38:57
问题 Stephan T Lavavej's initial proposal for make_unique was N3588 It included the following functions: make_unique<T>(args...) make_unique_default_init<T>() make_unique<T[]>(n) make_unique_default_init<T[]>(n) make_unique_value_init<T[]>(n, args...) make_unique_auto_size<T[]>(args...) However, the final propsal, N3656, only includes make_unique (both forms). I am unable to find any discussion on the other forms of the function. I read the minutes of the Bristol meeting, but they don't even