Data dodania Pytanie
2017-02-14 21:02 Why is the move constructor not called when moving in a lambda? »
I am trying to compile the following code: #include <utility> struct C2 { C2() = default; C2(C2 const&) = delete; ...
(1) odpowiedzi
2017-02-14 14:02 cost of (address) indirection to the same address many times (used in iterator) »
If I use indirection a lot, but the target has the same address, will the cost of indirection become near-zero? Example :- class C{ public...
(0) odpowiedzi
2017-02-14 14:02 Are modern C++ compilers able to avoid calling a const function twice under some conditions? »
For instance, if I have this code: class SomeDataProcessor { public: bool calc(const SomeData & d1, const SomeData & d2) const; private: ...
(4) odpowiedzi
2017-02-14 11:02 Why does the extern “C” group C++ class (not header) here? »
I was searching SVM libraries, which encounted BudgetedSVM. In the source code, I found an unusual usage, just like this: #sample.h #ifndef SAMPLE_...
(4) odpowiedzi
2017-02-13 15:02 How to use lambda as template argument with default value in C++? »
I want to do a simple thing: void DoUntil(auto predicate = [] { return false; }); Obviously this doesn't work - I have to use a template argument: ...
(2) odpowiedzi
2017-02-13 15:02 How come the definition order is not followed when defining static member variables? »
I know about the problem of the order of initialization of static variables from different translation units. However, my problem is within one transl...
(1) odpowiedzi
2017-02-13 12:02 Why isn't enable_if working here? »
I have this code, my expectation is that there would be two different versions of operator () based on the type of the template parameter. #include &...
(1) odpowiedzi
2017-02-13 08:02 How to apply ReSharper Ultimate Naming Styles for C++ »
I don't know how to apply naming style for C++ language in Resharper Ultimate Extension for Visual Studio 2015 Update 3. My OS is Windows 10. Everythi...
(1) odpowiedzi
2017-02-12 19:02 Why can't I use an brace-enclosed list as an operand to an overloaded operator? »
I'm working with a set of custom C++ libraries that provides a type representing a sequence. There's an overloaded operator+ that takes in two sequenc...
(0) odpowiedzi
2017-02-12 15:02 Invalid use of move? »
Could somebody give me hints on why this code doesn't output anything? I'm assuming it has something to do with the move line... #include <iostr...
(2) odpowiedzi
2017-02-12 11:02 Why the "begin/end" vs "first/last" discrepancy? »
Why do containers offer "begin"/"end" iterators while algorithms want "first"/"last" iterators? For example: vector offers .begin() and .end() (cpp...
(3) odpowiedzi
2017-02-11 17:02 will casting around sockaddr_storage and sockaddr_in break strict aliasing »
Following my previous question, I'm really curious about this code - case AF_INET: { struct sockaddr_in * tmp = reinterpret_...
(2) odpowiedzi
2017-02-11 11:02 Is shufps slower than memory access? »
The title may seem nonsense but let me explain. I was studying a program the other day when I encountered the following assembly code: movaps xmm3, ...
(1) odpowiedzi
2017-02-11 01:02 C++ rand () not providing correct number based on seed »
I am working on a C++ assignment for my class, and we have to use rand () with a seed of 99 to produce a set of values. However, my problem is that wh...
(3) odpowiedzi
2017-02-10 19:02 Guaranteed elision and chained function calls »
Let's say I have the following type: struct X { X& operator+=(X const&); friend X operator+(X lhs, X const& rhs) { lhs +=...
(2) odpowiedzi
2017-02-10 15:02 lvalue reference became invalid after passing through an identity function »
Would someone explain why the reference became invalid after going through an "identity" function, foo1? Isn't an "address" to A is passed into and r...
(2) odpowiedzi
2017-02-10 11:02 Thread safety of std::random_device »
I have some code which looks a bit like this: std::random_device rd; #pragma omp parallel { std::mt19937 gen(rd()); #pragma omp for for(...
(1) odpowiedzi
2017-02-09 22:02 C++ - Alphabetical order »
Why won't my code work properly? I'm basically trying to order a string in alphabetical order, however this seemed to be more advanced than I had ever...
(1) odpowiedzi
2017-02-09 22:02 C++11 atomic bool fails to protect non-atomic counter »
I encountered an issue with a (basic) spinlock mutex that does not seem to work as expected. 4 threads are incrementing a non-atomic counter that is ...
(0) odpowiedzi
2017-02-09 11:02 Why does nobody ever seem to write `delete &someObj`? »
Ok, this may seem ridiculous but I so often see code where dynamically allocated memory deleted using a reference looks like this: Obj* ptr = &so...
(3) odpowiedzi
2017-02-09 10:02 About safe operations involving unique pointers »
Consider the following code: #include <memory> struct Foo { std::unique_ptr<Foo> next; }; void f(Foo &foo) { foo = std::move(*foo.ne...
(1) odpowiedzi
2017-02-08 14:02 Is remove_if and then erase efficient on vector? »
Although there are tens of questions about remove_if + erase for vector. I couldn't find what is the performance of such action. When I write: m...
(3) odpowiedzi
2017-02-08 14:02 Static assertion for a move constructor different from the copy constructor »
Imagine that I have a class A that is cheap to move and expensive to copy. It could look like class A { public: [...] private: HeavyCla...
(3) odpowiedzi
2017-02-08 14:02 Is there a convenience constructor in C++? »
Is it possible for an overloaded constructor to somehow call another constructor within the class, similar to the code below? class A { public: A...
(1) odpowiedzi
2017-02-08 09:02 What is constexpr in C++? »
I am really confused about a constexpr concept, as I have read constexpr is evaluated at compile time, so it is useful for performance optimization ve...
(4) odpowiedzi
2017-02-07 21:02 Expected "warning: unused variable" but nothing is generated in C++ »
Test code: struct X { X (int x) {} }; int main() { X x1(0); // nothing! X x2 = 0; // warning: unused variable X x3 = X(0); //...
(2) odpowiedzi
2017-02-07 11:02 Lambda capture and parameter with same name - who shadows the other? (clang vs gcc) »
auto foo = "You're using g++!"; auto compiler_detector = [foo](auto foo) { std::puts(foo); }; compiler_detector("You're using clang++!"); clang++ 3...
(2) odpowiedzi
2017-02-07 06:02 Where to use std::variant over union? »
Please explain what is the difference between union and std::variant and why std::variant was introduced into the standard? In what situations should...
(1) odpowiedzi
2017-02-06 21:02 Why is my swap<string,string> far slower than the std version? »
This is my C++ code: inline static void swap(std::string& a1, std::string& a2) { std::string temp( std::move(a1)); a1 = std::move...
(1) odpowiedzi
2017-02-06 21:02 Why this ADL case is working? »
How does find_type know where the function typemap is? The argument it receives is not from that namespace, it's from the std namespace! #include &lt...
(2) odpowiedzi
2017-02-06 12:02 Is constructed string("Plain Old C chain") a rvalue? »
I was wondering if a copy elision is made in the call of foo(string) below. (Note: foo(string) belongs to an interface that I can not change). For th...
(2) odpowiedzi
2017-02-06 08:02 C++ Multithreading: is initialization of a local static lambda thread safe? »
The C++11 standard says about local static variable initialization that it is supposed to be thread safe (http://en.cppreference.com/w/cpp/language/st...
(3) odpowiedzi
2017-02-05 12:02 Why does C++ allow you to move classes containing objects with deleted move operations? »
Why am I allowed to use std::move on a class which contains fields of a type with deleted move semantics (case 1), but am not allowed to use it on an ...
(1) odpowiedzi
2017-02-05 06:02 Does the defaulted default constructor initialize variables to zero? »
I'm updating a class to C++14, and trying to figure out the simplest way to initialize all of the instance variables to zero on construction. Here's w...
(2) odpowiedzi
2017-02-05 05:02 Why is a template<typename...> not recognized as instantiatable through template<template<typename> typename>? »
I'm trying to arbitrarily "bind" template parameters but have run into an elegance problem. To cut straight to the underlying problem, gcc 6.2 has a ...
(2) odpowiedzi