Data dodania Pytanie
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
2017-05-28 22:05 Boost python getter/setter with the same name »
I am wrapping C++ classes with boost-python and I am wondering is there is a better way to do it than what I am doing now. The problem is that the cl...
(1) odpowiedzi
2017-05-28 18:05 How to decide if a template specialization exist »
I would like to check if a certain template specialization exist or not, where the general case is not defined. Given: template <typename T> s...
(1) odpowiedzi
2017-05-28 14:05 Generalized copy constructors »
Why do classes like shared_ptr have another template in their constructors? For example: template<class T> class shared_ptr { public: templa...
(2) odpowiedzi
2017-05-28 08:05 Instantiating a template function in all M * N combinations »
Imagine I have M methods that I want to time, along with N timing methods (let's call them clock implementations)1. The exact details aren't too impor...
(2) odpowiedzi
2017-05-27 19:05 Perfect forwarding of variables declared with structured binding »
I have a struct template <typename T> struct Demo { T x; T y; }; and I'm trying to write a generic function similar to std::get for t...
(2) odpowiedzi
2017-05-27 15:05 Why are there 128bit load functions for SSE? »
I'm poking around in somebody else's code and currently trying to figure out why _mm_load_si128 exists. Essentially, I tried replacing _ra = _mm_lo...
(1) odpowiedzi
2017-05-27 15:05 Does <algorithm> define a macro X? »
I tried to compile the code with option C++14: #define X static_cast<double>(2) #include <algorithm> // if you change the two lines, no e...
(1) odpowiedzi
2017-05-26 21:05 Extending the life of a temporary object by getting a reference to a subobject »
There is a subtle difference between the language used at cppreference.com and by the C++11 Standard regarding when the life of a temporary object is ...
(0) odpowiedzi
2017-05-26 18:05 How can I get the penultimate element in a list? »
I have a std::list<double> foo; I'm using if (foo.size() >= 2){ double penultimate = *(--foo.rbegin()); } but this always gives me a...
(3) odpowiedzi
2017-05-26 14:05 Are public variables faster than using getters and setters? »
I am writing a custom physics engine for a game that I am making, my physics object class has tons of variables (distance, velocity, acceleration, mas...
(2) odpowiedzi
2017-05-26 10:05 How can I simplify this redundant C++ code? »
There are two existing classes, one is SrcField which returns the concrete type value, and the other is a union DSTField, that defines the correspondi...
(2) odpowiedzi
2017-05-25 18:05 QTextEdit takes an increasing amount of time to draw the text »
I am using a QTextEdit, and I update the text (specifically setHTML) at a 1Hz rate. Initially the setHtml method is fast (only a few ms); but after 1...
(1) odpowiedzi
2017-05-25 17:05 How to avoid if / else if chain when classifying a heading into 8 directions? »
I have the following code: if (this->_car.getAbsoluteAngle() <= 30 || this->_car.getAbsoluteAngle() >= 330) this->_car.edir = Car::E...
(9) odpowiedzi
2017-05-25 08:05 Is it possible to use anonymous classes in C++? »
I have seen anonymous classes in C++ code on Quora. It's successfully compiled and run. Code here: #include <iostream> auto func() { clas...
(3) odpowiedzi
2017-05-25 01:05 Explicit default constructors in C++17 »
In C++17, empty tag types in the standard library now have default constructors which are marked explicit, and are also = default. For example, std::p...
(1) odpowiedzi
2017-05-24 19:05 How to manage std::list elements as references? »
I have the following code: struct Foo { int var1; int var2; friend std::ostream& operator<<(std::ostream& os, const Foo&a...
(4) odpowiedzi
2017-05-24 12:05 How to call python from c++ »
I'm Python new comer. I tried to call a python script from c++ like this (in Raspberry Pi). std::string pythonCommand = "python Callee.py \""+a+"\" "...
(2) odpowiedzi
2017-05-24 11:05 What changes to C++ made copy initialization work for class with explicit constructor? »
Consider this code: struct X{ explicit X(){} explicit X(const X&){} }; void foo(X a = X()){} int main(){} Using C++14 standard, both ...
(1) odpowiedzi
2017-05-24 10:05 Does it make sense to add final keyword to the virtual function in a class that has no base class (is not derived) »
I am reading an awesome awesome C++11 tutorial and the author provides this example while explaining the final keyword: struct B { virtual void f...
(3) odpowiedzi
2017-05-23 13:05 Strict aliasing, -ffast-math and SSE »
Consider the following program: #include <iostream> #include <cmath> #include <cstring> #include <xmmintrin.h> using namespa...
(1) odpowiedzi
2017-05-23 10:05 Could I use operator == if I only implemented operator <? »
I have implemented operator< for a certain object. Logically, if !(a < b) and !(b < a) it means a == b. Is this inferred automatically? Can ...
(13) odpowiedzi
2017-05-23 03:05 Why do const shared_ptr<const T>& and const shared_ptr<T>& show different reference counts? »
For the following code snippet, it shows different reference counts in the methods. Could someone explain why these values are different? class Foo {...
(1) odpowiedzi