c++14

Redefinitions of constexpr static data members are allowed now? (but not inline const)?

女生的网名这么多〃 提交于 2019-12-31 20:18:09
问题 The following fails to compile under both gcc and clang in c++14, but succeeds with c++1z: struct Cls { static constexpr int N = 0; }; constexpr int Cls::N; constexpr int Cls::N; The C++14 error is predictable: redefinition of ‘constexpr const int Cls::N’ What changed to make this legal? I found: n4659 10.1.5 [dcl.constexpr] A function or static data member declared with the constexpr specifier is implicitly an inline function or variable So I thought it might have to do with inline variables

A using-declaration can not be repeated in function scope. Why is that?

℡╲_俬逩灬. 提交于 2019-12-31 19:26:30
问题 In [namespace.udecl]/10 you have the following example: namespace A { int i; } namespace A1 { using A::i; using A::i; // OK: double declaration } void f() { using A::i; using A::i; // error: double declaration } This snippet compiles in clang. 回答1: The first is a declaration inside a namespace, and the multiple using statements could happen frequently using #includes. The second is inside a definition of a function, and you would never do that unless you made a mistake. You can't define the

A using-declaration can not be repeated in function scope. Why is that?

别等时光非礼了梦想. 提交于 2019-12-31 19:23:51
问题 In [namespace.udecl]/10 you have the following example: namespace A { int i; } namespace A1 { using A::i; using A::i; // OK: double declaration } void f() { using A::i; using A::i; // error: double declaration } This snippet compiles in clang. 回答1: The first is a declaration inside a namespace, and the multiple using statements could happen frequently using #includes. The second is inside a definition of a function, and you would never do that unless you made a mistake. You can't define the

How to read a binary number as input?

旧城冷巷雨未停 提交于 2019-12-31 14:42:10
问题 Is there a way for the user to input a binary number in C or C++? If we write something like int a = 0b1010; std::cout << a << std::endl Then the output comes out to be 10 (when using the appropriate compiler extensions). but when we try to write int n; std::cin >> n; int t = 0bn; It gives us an error so can anyone suggest that how can we directly read binary number as input rather than using string to store input? 回答1: There is a bit of confusion here, let's disentangle it a bit. 0b1010 is

Assignment in C++ occurs despite exception on the right side

两盒软妹~` 提交于 2019-12-31 10:57:07
问题 I have some (C++14) code that looks like this: map<int, set<string>> junk; for (int id : GenerateIds()) { try { set<string> stuff = GetStuff(); junk[id] = stuff; } catch (const StuffException& e) { ... } } This works. Sometimes GetStuff() throws an exception, which works fine, because if it does, I don't want a value in the junk map then. But at first I'd written this in the loop, which doesn't work: junk[id] = GetStuff(); More precisely, even when GetStuff() throws an exception, junk[id] is

Merge macros C++?

[亡魂溺海] 提交于 2019-12-31 07:15:15
问题 I would like to know if it was possible to merge several macros in C++ Let me explain : I have an A macro that does not do anything at all. I want to add a macro B to A so that A = A + B, then I want to add a macro C to A so that A becomes A = A + C, and so that A contains B and C. I also want these operations to be done in different .h files and not in a single file like that : // in Component.h #define A class Component { } class myXmlParser { template <class T> void addComponent<T>() {

Did template concepts get to c++14?

﹥>﹥吖頭↗ 提交于 2019-12-30 18:42:48
问题 Concepts is nice feature that for example replaces ugly compiler error output when something is wrong with template instantiation with nice readable messages. Unfortunately they did not get to C++11 Does anybody know if it made it to C++14? 回答1: No, but this interview with Bjarne Strostrup says that they will be put into "Technical Specifications" that implementors may use. 来源: https://stackoverflow.com/questions/25387888/did-template-concepts-get-to-c14

Delayed Thread Start - Notify All Not Waking All Threads

扶醉桌前 提交于 2019-12-30 11:29:45
问题 attempting: To do a delayed start on multiple threads. problem: I've created the example below to prove out the idea and attempted to create a race codition on x to prove out that all the threads would run concurrently. It seems like things are serialize instead of running in parallel-the desired behavior, but maybe each thread runs for too short a period and finishes before the other onse get serviced Sometimes a thread will get stuck on the cv.wait --- I've viewed this in GDB and can see

Measure execution time of arbitrary functions with C++14 lambda

蹲街弑〆低调 提交于 2019-12-30 09:58:14
问题 I have been excited by item 24 of Scott Meyer's book "Effective Modern C++". He mentions the possibility to write a C++14 lambda to record the time taken in an arbitrary function invocation. I am still in an early of learning C++14 features. My attempt (Main.cpp) looks like this for measuring the time of a member function call: #include <chrono> #include <iostream> auto measure = [](auto&& function, auto&&... parameters) -> decltype(function) { const std::chrono::steady_clock::time_point

Vector initialization with double curly braces: std::string vs int

守給你的承諾、 提交于 2019-12-30 09:54:16
问题 In an answer to this question: Initializing vector<string> with double curly braces it is shown that vector<string> v = {{"a", "b"}}; will call the std::vector constructor with an initializer_list with one element . So the first (and only) element in the vector will be constructed from {"a", "b"} . This leads to undefined behavior, but that is beyond the point here. What I have found is that std::vector<int> v = {{2, 3}}; Will call std::vector constructor with an initializer_list of two