Data dodania Pytanie
2017-08-09 16:08 The value of a const variable is or is not usable in a constant expression, depending on the variable type »
The following code is fine: constexpr double square_cstxpr(double x) { return x * x; } int main() { const int test = 5; constexpr double res...
(2) odpowiedzi
2017-08-09 13:08 Define generic comparison operator »
I came up with the idea to define a generic comparison operator which would work with any type, for the fun of it. #include <cstring> #include ...
(3) odpowiedzi
2017-08-09 09:08 Confusion with hard error in SFINAE »
With regards to the following code (https://wandbox.org/permlink/nhx4pheijpTF1ohf reproduced below for convenience) #include <type_traits> #inc...
(1) odpowiedzi
2017-08-08 11:08 Why does passing the literal 3 choose the int overload instead of the short overload? »
How does C++ handle function overloading in this case? #include <iostream> void func(int x) { std::cout << "integer"; } void func(sh...
(5) odpowiedzi
2017-08-08 08:08 Is copy/move elision allowed when returning *&object? »
Look at this code: #include <stdio.h> struct Foo { Foo() { } Foo(const Foo &) { printf("copy\n"); } Foo(Foo &&) { prin...
(1) odpowiedzi
2017-08-08 02:08 c++ {*this} inside curly braces »
The following code compiles fine: g++ -std=c++11 test.cpp -Wall -Wextra -Wfatal-errors && ./a.out However, if I remove the curly braces fro...
(4) odpowiedzi
2017-08-07 19:08 C++17 And the Current State of Decimal Floating Point »
What is the current status of decimal floating point in C++? I am specifically looking for the status of language inclusion, standards compliance and...
(1) odpowiedzi
2017-08-07 09:08 C++ enum flags vs bitset »
What are pros/cons of usage bitsets over enum flags? namespace Flag { enum State { Read = 1 << 0, Write = 1 << 1, ...
(1) odpowiedzi
2017-08-07 09:08 Can the structured bindings syntax be used in polymorphic lambdas »
Structured bindings make it more clean and readable to iterate through a map with a range based for loop like below for (auto [key, value] : map) { ...
(1) odpowiedzi
2017-08-06 23:08 Performance cost to multiple OpenMP threads reading (not writing) a shared variable? »
In OpenMP (I am using C++), is there a performance cost if you have a shared (or even global) variable that is being repeatedly read (not written) by ...
(2) odpowiedzi
2017-08-06 19:08 Cannot initialize std::variant with various lambda expressions »
I'm playing with std::variant, lambdas and std::future, and got super weird results when I tried to compose them together. Here are examples: using v...
(1) odpowiedzi
2017-08-06 14:08 Why does this rvalue reference bind to an lvalue? »
I do not understand why the following code compiles on GCC 8.0: decltype(auto) foo(int&& r) { return r; } In foo, the declaration type ...
(1) odpowiedzi
2017-08-06 07:08 Trailing class template arguments not deduced »
The code below fails to compile with gcc 7.1.0, which complains about providing the wrong number of template arguments in the second line of main. Thi...
(1) odpowiedzi
2017-08-05 22:08 Unexpected senseless optimization tries of a simple for loop (in Visual C++ 2017) »
I was playing around with the Visual C++ 2017 compiler doing some tests on how to implement various things to get maximum performance from the code wh...
(0) odpowiedzi
2017-08-05 20:08 How to create a private static const string when using the pimpl idiom »
Background I have been learning how to implement the pimpl idiom using the newer c++11 method described by Herb Sutter at this page: https://herbsutt...
(2) odpowiedzi
2017-08-05 08:08 Special behavior for decltype of call operator for incomplete types »
I've been struggling with a compilation issue, and have been able to shrink the problem down to a small code segment. To set the stage, I'm trying to...
(1) odpowiedzi
2017-08-04 14:08 Consequences of uninitialised variables: int vs unsigned char »
I saw the following example on cppreference.com int x; // OK: the value of x is indeterminate int y = x; // undefined behavio...
(4) odpowiedzi
2017-08-04 13:08 Append int to std::string »
I tried two different ways to append an int to a std::string, and to my surprise, I got different results: #include <string> int main() { ...
(4) odpowiedzi
2017-08-04 05:08 What happens if 'throw' fails to allocate memory for exception object? »
From C++11 standard (15.1.p4): The memory for the exception object is allocated in an unspecified way, except as noted in 3.7.4.1 What if allo...
(2) odpowiedzi
2017-08-03 11:08 What are use cases for structured bindings? »
C++17 standard introduces a new structured bindings feature, which was initially proposed in 2015 and whose syntactic appearance was widely discussed ...
(2) odpowiedzi
2017-08-03 09:08 Same const type qualifier »
Having two const's for a type issues a warning / error. However if the type has been defined with typedef, the compiler accepts it (both Visual Studio...
(1) odpowiedzi
2017-08-03 09:08 How to divide a tuple in C++ »
I have a question about dividing a tuple, as the title said. In fact, I can do it using std::index_sequence, but the code looks ugly. Is there an el...
(1) odpowiedzi
2017-08-02 21:08 Why does the most negative int value cause an error about ambiguous function overloads? »
I'm learning about function overloading in C++ and came across this: void display(int a) { cout << "int" << endl; } void display(uns...
(3) odpowiedzi
2017-08-02 14:08 Template reference argument deduction failure »
Why following code doesn't compile in C++14 compiler? If I use const int i = 10; int n = fun(i); The compiler gives an error. But, If I use int ...
(2) odpowiedzi
2017-08-02 10:08 Performance of std::partial_sort() versus std::sort() when sorting the whole range? »
Is there a significant difference between the following two approaches? Way 1 uses sort or partial_sort, depending on the size of the vector while way...
(2) odpowiedzi
2017-08-02 10:08 Is this a clang bug or something I don't know about C++? »
While looking at this question I tried it out with clang and got in a weird situation. The following example: #include <string> class ACP { pu...
(1) odpowiedzi
2017-08-01 19:08 Return a local C-string for function with C++ string return value »
The following piece of code compiles and runs without errors and with the expected output: #include <string> #include <iostream> using na...
(1) odpowiedzi
2017-08-01 10:08 sending IOKit command with dynamic length »
I'm using IOKit framework to communicate with my driver using IOConnectCallMethod from the user-space client and IOExternalMethodDispatch on the drive...
(2) odpowiedzi
2017-08-01 08:08 Why can't fold expressions appear in a constant expression? »
Consider the following code: template<int value> constexpr int foo = value; template<typename... Ts> constexpr int sum(Ts... args) { ...
(3) odpowiedzi
2017-07-31 17:07 Is there a way to build C++ custom qualifiers? »
Is there any way to implement a custom type qualifier (similar to const)? I would like to only allow function calls to functions that are of the right...
(1) odpowiedzi
2017-07-31 10:07 Expression 'i < 0' is always false »
For the following snippet: size_t i = 0; std::wstring s; s = (i < 0) ? L"ABC" : L"DEF"; s = (i != -1) ? L"ABC" : L"DEF"; PVS-Studio analysis l...
(4) odpowiedzi
2017-07-31 09:07 What is the type of a pointer to a 2D array? »
I know that the following is not correct: int arr[2][3] = {}; //some array initialization here int** ptr; ptr = arr; But I am quite surprised that ...
(4) odpowiedzi
2017-07-30 18:07 C++ overloading and overriding »
This code generates the following compilation error : error: no matching function for call to 'C::print(int)' can you help me figuring out the ...
(3) odpowiedzi
2017-07-30 18:07 Composing class of several classes in C++ at runtime »
For a parser I'm developing I am parsing an event log. In the log, each line is an event, which makes it easy to parse the file line by line. The even...
(1) odpowiedzi
2017-07-30 14:07 g++ and clang++ different behaviour infering the template return type of a function »
Another "who's right between g++ and clang++?" question for C++ standard gurus. The following program #include <iostream> void foo (int v) {...
(0) odpowiedzi