Data dodania Pytanie
2017-06-07 19:06 Why does the compiler not give an ambiguous reference error? »
With reference to the following code #include <iostream> #include <tuple> #include <string> #include <type_traits> using st...
(2) odpowiedzi
2017-06-07 17:06 Is this-> mandatory to access Base<T> identifiers from derived classes? »
This code compiles with MSVC 2015, but doesn't compile with Clang 5.0.0 (trunk 304874): template <typename T> struct Base { T data; }; templ...
(2) odpowiedzi
2017-06-07 15:06 Why is Range-v3 slower than the STL in this example? »
I'm playing around with the Range-v3 library to perform a glorified find_if and was curious why google-benchmark consistently ranks my Range-v3 code w...
(1) odpowiedzi
2017-06-06 14:06 Fail to run project with Xcode 9 , Many new C++ semantic issue »
My project works fine in Xcode 8. When I build It in Xcode 9, there are many C++ semantic issues reported.It seems Xcode 9 C++ complier do much strict...
(1) odpowiedzi
2017-06-06 11:06 GCC and Clang disagree about C++17 constexpr lambda captures »
Consider this example which declares a variable as constexpr, captures it by copy in a lambda, and declares another constexpr variable which is the re...
(1) odpowiedzi
2017-06-06 05:06 When the dereference operator (*) is overloaded, is the usage of *this affected? »
For example, class Person{ string name; public: T& operator*(){ return name; } bool operator==(co...
(2) odpowiedzi
2017-06-06 00:06 c++ how to initialize const elements of an array »
i need a way to initialize const elements of an array for the program i am currently working on. The problem is that i have to initialize these elemen...
(3) odpowiedzi
2017-06-05 15:06 Compiler optimization: g++ slower than intel »
I recently acquired a computer with dual-boot to code in C++. On windows I use intel C++ compiler and g++ on linux. My programs consist mostly of comp...
(2) odpowiedzi
2017-06-05 13:06 Using std::array and using "array" as name »
In my C++ JSON library, I recently had a regression with GCC7. I stripped down the affected code and hope to understand the error. The code Consider...
(0) odpowiedzi
2017-06-05 11:06 Why isn't arr[-2] equivalent to -2[arr]? »
#include <iostream> using namespace std; int main() { int arr[3] = { 10, 20, 30 }; cout << arr[-2] << endl; cout <&...
(3) odpowiedzi
2017-06-04 19:06 Why use std::forward in concepts? »
I was reading the cppreference page on Constraints and noticed this example: // example constraint from the standard library (ranges TS) template &lt...
(2) odpowiedzi
2017-06-04 14:06 How to use a future without waiting for it? »
The following example is taken from a C++ async tutorial: #include <future> #include <iostream> #include <vector> int twice(int m)...
(2) odpowiedzi
2017-06-04 13:06 Using `std::min` as an algorithm parameter »
So I ran into this problem: I need to replace every element of the std::vector<int> with the minimum of whatever came before it (inclusive). ...
(2) odpowiedzi
2017-06-04 03:06 how to hide local variables »
In my code, sometimes there's a long function, to avoid messed up the local variables, i would use a pair of braces to embrace the details so the loca...
(1) odpowiedzi
2017-06-03 20:06 Using decltype to declare the entire function type itself (not pointer!) »
So I have a function with a specific signature in a header file, and I want to declare another function with the exact same signature inside a class w...
(1) odpowiedzi
2017-06-03 12:06 Why is this C++ code execution so slow compared to java? »
I recently wrote a computation-intensive algorithm in Java, and then translated it to C++. To my surprise the C++ executed considerably slower. I have...
(2) odpowiedzi
2017-06-03 08:06 Behaviour of arr[i] = i++ and i = i + 1 statements in C and C++ »
In the C and C++ languages, the arr[i] = i++; statement invokes undefined behavior. Why does the statement i = i + 1; not invoke undefined behavior? ...
(5) odpowiedzi
2017-06-02 14:06 What's the closest thing in C++ to retroactively defining a superclass of a defined class? »
Suppose I have the class class A { protected: int x,y; double z,w; public: void foo(); void bar(); void baz(); }; defined and ...
(5) odpowiedzi
2017-06-02 11:06 RAII vs. Garbage Collector »
I recently watched a great talk by Herb Sutter about "Leak Free C++..." at CppCon 2016 where he talked about using smart pointers to implement RAII (R...
(11) odpowiedzi
2017-06-02 10:06 Why must virtual base classes be constructed by the most derived class? »
The following code won't compile: class A { public: A(int) {} }; class B: virtual public A { public: B(): A(0) {} }; // most derived class ...
(3) odpowiedzi
2017-06-01 22:06 Is Java ArrayList really this much slower than C++ vector? »
I do not want to start yet another pointless flamewar about whether Java or C++ is the better language in general. I want to know whether a comparison...
(1) odpowiedzi
2017-06-01 17:06 Is the move constructor called after invoking a conversion function? »
Consider this example: struct T { }; struct S { operator T(); }; S s; T t = s; [dcl.init] will take us to [over.match.copy] which will find t...
(1) odpowiedzi
2017-06-01 13:06 Copy initialization of the form '= {}' »
Given the following: #include <stdio.h> class X; class Y { public: Y() { printf(" 1\n"); } // 1 // operator X(); // 2 }; cl...
(2) odpowiedzi
2017-06-01 01:06 Confusion with commas in ternary expression »
I found the following interesting code today: SomeFunction(some_bool_variable ? 12.f, 50.f : 50.f, 12.f) I created a small sample to reproduce the ...
(3) odpowiedzi
2017-05-31 23:05 Dependent type or argument in decltype in function definition fails to compile when declared without decltype »
I've been playing with deduced return types in definitions that resolve to the same type as the declaration. This works: template <typename> st...
(0) odpowiedzi
2017-05-31 22:05 Does this const reference have its life preserved? »
I have found this answer to the question "Does a const reference prolong the life of a temporary?", which states: Only local const references prol...
(3) odpowiedzi
2017-05-31 18:05 In which thread is the terminate handler called? »
In which thread is called the terminate handler: when an exception is thrown inside a noexcept function? when the user call std::terminate()? at sta...
(1) odpowiedzi
2017-05-31 16:05 When should we align our data and when does the compiler do it for us? »
Alignment of data (and instructions) is still fairly critical to high performance computing, according to the Intel optimization manuals. I am aware ...
(0) odpowiedzi
2017-05-30 23:05 Opengl Render Order »
I have an Opengl application which renders a scene model by model. If, say, I render a model at the front first and then render a model at the back d...
(2) odpowiedzi
2017-05-30 18:05 Is stateful metaprogramming ill-formed (yet)? »
One of my most beloved/evil inventions I've had the fortune to come across is the constexpr counter, aka stateful metaprogramming. As mentioned in the...
(1) odpowiedzi
2017-05-30 15:05 Matching variadic non-type templates »
Let's say I have two structs, Foo and Bar: template<int...> struct Foo{}; template<unsigned long...> struct Bar{}; I want to create a ...
(3) odpowiedzi
2017-05-30 14:05 Method call acting unexpectedly like an l-value »
Can anybody explain why this code compiles: typedef struct longlong { unsigned long low; long high; } longlong; typedef longlong Foo; struc...
(4) odpowiedzi
2017-05-29 18:05 How to ensure a specific class only can create an instance of another class? »
How can I restrict the instantiation of a class from only within a specific class? I don't want to restrict it within a single file, so anonymous nam...
(2) odpowiedzi
2017-05-29 13:05 how to read extreme long lines from text file fast and safe in C++? »
There is a large text file of 6.53 GiB. Each line of it can be a data line or comment line. Comment lines are usually short, less than 80 characters, ...
(3) odpowiedzi
2017-05-29 05:05 How to avoid undefined behaviour with aligned_storage and polymorphism »
I have some code that basically do this: struct Base { virtual ~Base() = default; virtual int forward() = 0; }; struct Derived : Base { ...
(3) odpowiedzi