c++14

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

泄露秘密 提交于 2019-12-05 01:42:45
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::result_of_t<F( FArgs... )> { return std::forward<F>( f )( std::forward<FArgs>( f_args )... ); }; My attempt

Use of deleted copy constructor in the singleton

◇◆丶佛笑我妖孽 提交于 2019-12-05 01:35:58
问题 I've implemented the singleton pattern like this, there is my code: header file: class Settings_manager{ public: static Settings_manager& get_instance(); void operator=(Settings_manager const&) =delete; Settings_manager(Settings_manager const&) =delete; ... private: Settings_manager(); }; implementation: Settings_manager& Settings_manager::get_instance() { static Settings_manager instance; return instance; } Settings_manager::Settings_manager() { read_file(); } When I try use get_instance

Changing active member of union in constant expressions

自闭症网瘾萝莉.ら 提交于 2019-12-05 01:00:48
问题 Playing with constexpr and union I found out, that I can't change active member of an union in constexpr . Just one exception: union of empty classes. constexpr bool t() { struct A {}; struct B {}; union U { A a; B b; } u{}; u.a = A{}; u.b = B{}; return true; } static_assert(t()); constexpr bool f() { struct A { char c; }; struct B { char c; }; union U { A a; B b; } u{}; u.a = A{}; u.b = B{}; // error originating from here return true; } static_assert(f()); First function may produce constant

Is assert usable in constant expressions?

六月ゝ 毕业季﹏ 提交于 2019-12-05 00:21:33
The assert -macro from <cassert> provides a concise way of ensuring that a condition is met. If the argument evaluates to true , it shall not have any further effects. However, can its invocation also be used inside a constant expression in that case? This was dealt with by LWG 2234 , which was brought back to attention after relaxed constraints on constexpr functions had been introduced. Proposed resolution : This wording is relative to N3936. Introduce the following new definition to the existing list in 17.3 [definitions]: constant subexpression [defns.const.subexpr] an expression whose

Approach for automatic fields reordering in C-like structs

天涯浪子 提交于 2019-12-05 00:21:20
问题 Is there a way to perform automatic fields reordering in C-like structs? I mean the using of the language features like( preprocessor for C and C++ and templates/type traits/etc for C++), which make it possible to do the following macro (Boost.Fusion-like style to adapt structures): REARRANGE(StructureName, (int8_t)(FieldName1), (int32_t)(FieldName2), (int16_t)(FieldName3), (int32_t)(FieldName4)); // is equivalent to (without loss of generality): struct StructureName { int32_t FieldName2;

Is it possible to ignore the trailing return type feature of c++11 in favor of the function return type deduction feature of c++14?

独自空忆成欢 提交于 2019-12-05 00:17:08
When I skip the return type of an expression The following code in C++11 : auto function(X x, Y y) -> decltype(x + y) { return x + y; } Is equal to the following code in C++14 : decltype(auto) function(X x, Y y) { return x + y; } But additionally it is possible to deduce the return type without decltype rules in C++14 : auto function() { return 0; } When I know what the return type is exactly The following code in C++11 : auto function() -> int { return 0; } Is equal to the following code in C++03 : int function() { return 0; } A strange example that should never happen The following code in C

C++14 support in QtCreator with Clang

夙愿已清 提交于 2019-12-05 00:00:53
问题 How can I enable C++14 support in QtCreator 3.3 using Clang 3.5? I have added a Clang kit and I have added CONFIG += c++14 in my project file. However when using e.g. return type deduction I get the following error: error: 'auto' return without trailing return type; deduced return types are a C++1y extension 回答1: you can use CONFIG += c++14 in .pro file with Qt5.5 but there is a bug with clang, so we need to modify the Qt/5.5/clang_64/mkspecs/features/c++14.prf file, add this code before

Xcode 5.1 enable C++14

半腔热情 提交于 2019-12-04 23:57:19
Xcode 5.1 using Clang 3.4. And Clang 3.4 supports C++14. However, I've been surfing though all of the Xcode options and don't see a way to enable C++14. I'm trying to enable the relaxed constexpr feature of C++14 To get this to work, you first set "C++ Language Dialect" to "compiler default". Then in "Other C++ flags" add "-std=c++1y". This will allow Clang++ to compile with c++14 from within Xcode. I tested this with Xcode 5.1.1 using the new user defined literal for basic_string: std::string word = "hello"s; Update: As of Xcode 6, c++14 is available as a first-class language dialect. With

decltype(auto) vs auto&& to perform generic handling of function's return type

烈酒焚心 提交于 2019-12-04 23:40:01
问题 When using auto&& to handle a function returning an lvalue: int func() { int v=42; return v; } auto && v = func(); What are the consequences of treating v as a reference instead of an lvalue? Do these consequences justify the use of decltype(auto) instead of auto&& to perform generic handling of function's return type? 回答1: auto&& is already optimal for capturing function return values, such that the differences of decltype(auto) can only be disadvantages. In your example, lifetime extension

Pointer-like classes and the ->* operator

血红的双手。 提交于 2019-12-04 23:33:42
I've recently come across the need to apply a pointer-to-member to the object designated by an iterator. I've tried the natural syntax : ite->*ptr = 42; To my dismay, it didn't compile. Iterators don't overload operator->* , but more surprisingly neither do smart pointers. I needed to resort to the following clunkiness : (*ite).*ptr = 42; Experimenting (see the live example below) has shown that such a syntax seems to be achievable for custom classes, for both pointers-to-members and pointers-to-member-functions, at least since C++14. Thus : Is there a reason the standard pointer-like classes