c++14

Using the detection idiom to determine whether a type has a constructor with a specific signature

南楼画角 提交于 2019-12-14 03:55:13
问题 I'm playing with the proposal of standard library support for the C++ detection idiom. It is a trait-like metafunction that determines whether a type T has a type member named T::type or a member function with a specific signature, e.g.: #include <iostream> template<class...> using void_t = void; template<class, template<class> class, class = void_t<>> struct detect : std::false_type { }; template<class T, template<class> class Operation> struct detect<T, Operation, void_t<Operation<T>>> :

Removing mutations for D metaprogramming/compiletime array generation

邮差的信 提交于 2019-12-14 02:38:46
问题 My plan is to write a mutation-less code in D-language so that my values are available by runtime. Someone spoke to me about loop-unrolling and compile time code generation but I have no clear idea how to do that. I have made the D-template below but it has no guarantee to be evaluated at compile-time because on the two assignment statements(mutations) . Advice would be greatly appreciated. Suggestions could be preferably in D or C++ without macros. import std.stdio; import std.string; import

Division in Variable Template Returns Zero in Visual Studio 2017

断了今生、忘了曾经 提交于 2019-12-14 01:29:01
问题 This is probably a visual-studio-2017 bug related to this question: Templated Variables Bug With Lambdas in Visual Studio? And as mentioned in the comments there seems to be optimizer related. Division in the definition of a variable template seems to have a bug in Visual Studio 2017. So this code for example: template <typename T> const T PI = std::acos(static_cast<T>(-1)); template <typename T> const T ONE_EIGHTY = 180; template <typename T> const T DEG_TO_RAD = PI<T> / ONE_EIGHTY<T>; int

Why forwarding return value is needed

一笑奈何 提交于 2019-12-14 00:19:23
问题 In the doc of std::forward , it gave the following example: template<class T> void wrapper(T&& arg) { foo(forward<decltype(forward<T>(arg).get())>(forward<T>(arg).get())); } Why is forwarding of return value needed here? What's the cases where it is different to the following code: template<class T> void wrapper(T&& arg) { foo(forward<T>(arg).get()); } 回答1: Let's break down the possibilities. T::get could return an lvalue reference (which is an lvalue expression), an rvalue reference (which

Refactor a condition [closed]

丶灬走出姿态 提交于 2019-12-14 00:10:51
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . There is a condition for a,b,c,d,e,f,g of type unsigned int given as follows: if ((a > 0) and (b < a) and (c >= d)) { return ((e < std::min(std::max(0, a - g), b)) and (f < std::min(d, std::max(0, c - g)))); } I am looking for the way of refactoring the expression to make it more

Reducing boilerplate when creating functor objects for std template functions

走远了吗. 提交于 2019-12-13 17:57:25
问题 As a solution to another question it seems useful to create "generic functor objects" which wrap various standard (and perhaps user-defined) template functions in a functor object. These are sometimes more useful than the corresponding template functions because the specific type of the function is "bound late" when passed as a functor object: only at the call site within the callee, rather than at the caller. For example, you cannot pass std::min as a functor object, you must pass a

wrong type deduction of function signature

我的未来我决定 提交于 2019-12-13 16:55:00
问题 I stumbled on a strange phenomenon while developping a templated API for accessing the windows registry. I thought I was smart by 'capturing' the ascii and unicode versions of the windows API in static constexpr 'variabeles' of 2 t_api structs ( t_api_A and t_api_W ). Everything was compiling fine ,but running not so much (exceptions on calling the 'captured functions'). So I used a piece of code (from Scott Meyers' book "Effective Modern C++") to see the deducted types. Apparently if I place

Why are template (non-static) member variables not supported in C++?

依然范特西╮ 提交于 2019-12-13 16:16:35
问题 While static member variables can be templated in C++14 this wont work: class SomeClass { public: template<typename T> T var = {}; }; int main() { SomeClass instance; instance.var<int> = 50; instance.var<double> = 0.1; } What are the reasons, that templates for variable members are not supported by the C++ standard since it should be possible in principle? 回答1: When you instantiate the class you don't know how much memory it will use. Does this class contain an int and a double? What if you

What are best practices for simple random shuffling in code that's both C++03 and C++14?

≡放荡痞女 提交于 2019-12-13 13:57:26
问题 Background: I'm shuffling the elements of a vector for a simple game. It should be possible to play the same game over again by passing the same integer seed — and vice versa, different seeds should produce different games. Cryptographic security (or any rigor at all) is not a design goal; cleanliness of code is a design goal. C++98/C++03 introduced std::random_shuffle , which is used like this: int seed = ...; std::srand(seed); // caveat, see below std::vector<int> deck = ...; std::random

How to build Qt 5 from source with c++14 support

前提是你 提交于 2019-12-13 12:32:05
问题 I am attempting to build Qt 5.4.1 pulled from git with the -std=c++14 flag for gcc4.9. But I am not sure about how to properly pass the flag into the build process. I have read that adding CONFIG += c++14 to a qt project file should work since Qt5.4, so I have added it into the qt.pro located in the top folder. But Qt is still compiled with -std=c++0x (c++11). 回答1: If you using g++ or clang++ to build the Qt 5 , then go to qt5/qtbase/mkspecs/common/g++-base.conf or qt5/qtbase/mkspecs/common