Data dodania Pytanie
2017-04-22 23:04 Why can a char pointer variable be initialized to a string but an int pointer variable can not be initialized to an array of integers? »
I am trying to understand the relationship between strings, arrays, and pointers. The book I am reading has a program in which it initializes a vari...
(3) odpowiedzi
2017-04-22 23:04 Guarantees of reordering of a vector »
Say I have this code: #include <iostream> #include <vector> int main() { std::vector<int> vec {10, 15, 20}; auto itr = ve...
(3) odpowiedzi
2017-04-22 19:04 Why would you combine two 32 bit integers into a 64 bit integer? »
Recently I saw how a compiler combined two 32 bit integers which were values of properties of a class and stored them as a 64 bit integer. My question...
(2) odpowiedzi
2017-04-22 12:04 C++ using global variable shows 100% slower than a pointer, when using pthread? »
I've got a quite program to show the performance of 2 similar programs, both uses 2 threads to do calculation. The core difference is that one uses a ...
(0) odpowiedzi
2017-04-21 22:04 Has a std::byte pointer the same aliasing implications as char*? »
C++ (and C) strict aliasing rules include that a char* and unsigned char* may alias any other pointer. AFAIK there is no analogous rule for uint8_t*....
(1) odpowiedzi
2017-04-21 12:04 Using Boost.Lockfree queue is slower than using mutexes »
Until now I was using std::queue in my project. I measured the average time which a specific operation on this queue requires. The times were measur...
(1) odpowiedzi
2017-04-21 12:04 Is it possible to avoid use of virtual method call in this case? »
I have a type of data that must be stored in a contiguous array which is iterated over for the purpose of updating that data. The tricky part is that ...
(4) odpowiedzi
2017-04-21 10:04 Why does Array elements have to be of the same type »
Array DS requires all its members to have the same time. Java throws ArrayStoreException when an attempt has been made to store the wrong type of obje...
(3) odpowiedzi
2017-04-21 09:04 Possible Deadlock on Calling FreeLibrary »
I have to write a DLL in Delphi XE7. I want to use TParallel.For in the DLL. The DLL is loaded into a C++ application, where everything works. However...
(1) odpowiedzi
2017-04-20 23:04 Deducing class template arguments with a constructor that uses a member type alias »
So apparently this is supposed to work: template<class T> struct C { using value_type = T; C(value_type); }; C c(1); // C<int> A...
(2) odpowiedzi
2017-04-20 14:04 Should a C++ pure virtual class need a definition? »
Consider: // in header.h class A { public: virtual ~A() = 0; }; class B : public A { public: ~B() override {} } The linker reports that i...
(4) odpowiedzi
2017-04-20 00:04 Is there any way to enforce that instances are only ever on the stack? »
I have a C++ class for which I only ever want it to be instantiated on the stack. I am using an api to access content that was developed in another (...
(3) odpowiedzi
2017-04-19 16:04 "Uninitialized captured reference" error when using lambdas in fold expression - clang vs gcc »
Consider the following code: template <typename F, typename X0, typename X1, typename... Xs> auto fold_left(F&& f, X0&& x0, X1&...
(1) odpowiedzi
2017-04-19 12:04 Inheriting from standard library type traits »
When writing custom type traits, I often derive them from the standard library type traits as follows: template<typename T> struct some_type_tr...
(1) odpowiedzi
2017-04-19 12:04 What is the rationale behind ADL for arguments whose type is a class template specialization »
I've spent some time trying to realize why my code doesn't compile and I've realized that in C++ Argument Dependent Lookup uses template typename argu...
(2) odpowiedzi
2017-04-19 00:04 Why aren't std::count and std::find optimised to use memchr? »
I was reading sehe's answer to this question and was surprised to see sehe found using a hand written loop using std::memchr to be over 3 times faster...
(0) odpowiedzi
2017-04-18 20:04 Are functions calls in a constructor's initializer-list sequenced? »
Consider: int f () { static int i = 0; return i++; } struct Test { int a, b; Test () : a(f()), b(f()) {} }; Test t; I know that a...
(2) odpowiedzi
2017-04-18 13:04 How does Eric Niebler's implementation of std::is_function work? »
Last week Eric Niebler tweeted a very compact implementation for the std::is_function traits class: #include <type_traits> template<int I&g...
(1) odpowiedzi
2017-04-18 10:04 Why is a const variable sometimes not required to be captured in a lambda? »
Consider the following example: #include <cstdlib> int main() { const int m = 42; [] { m; }(); // OK const int n = std::rand(); ...
(3) odpowiedzi
2017-04-17 21:04 How to deal with reference arguments that may point to internal data? »
More than once I've tracked down a rather baffling bug only to find it was due to a const reference parameter changing value part way through a method...
(2) odpowiedzi
2017-04-17 17:04 Why doesn't std::remove_const remove const qualifier? »
Note that I use std::thread just to get readable types in the errors: int main() { const int * first; using deref = decltype(*first); std...
(1) odpowiedzi
2017-04-17 14:04 Accessing a class array element with . in C++ or mistake in Stroustrup book »
In the book Programming Principles and Practice with C++ by B. Stroustrup I have come across a piece of code where the argument is the array of a basi...
(0) odpowiedzi
2017-04-17 01:04 What is __memset_sse2 and why does it perform so many instructions? »
I have two C++ implementations of an algorithm, call them A and B. The only difference between A and B is that A uses std::unordered_map<int, int&g...
(1) odpowiedzi
2017-04-16 22:04 In new code, why would you use `int` instead of `int_fast16_t` or `int_fast32_t` for a counting variable? »
If you need a counting variable, surely there must be an upper and a lower limit that your integer must support. So why wouldn't you specify those lim...
(2) odpowiedzi
2017-04-16 18:04 What's the point of (void) first2++ here? »
On this page of en.cppreference there are examples of possible implementation of lexicographical comparison. Here is the basic one: template<class...
(1) odpowiedzi
2017-04-16 15:04 std::sort by unary mapping »
The C++ standard library offers to pass a Comparator to std::sort. However, I have many cases in my code where I want to sort a list of T objects by a...
(2) odpowiedzi
2017-04-15 22:04 Why does calling a functor with an undeclared variable work? »
class foo { public: bool operator () (int & i) { return true; } }; int main() { foo(WhyDoesThisCompile); return 0; } ...
(1) odpowiedzi
2017-04-15 22:04 Deduction guides and variadic class templates with variadic template constructors - mismatched argument pack lengths »
Consider the following class definition and deduction guide: template <typename... Ts> struct foo : Ts... { template <typename... Us>...
(1) odpowiedzi
2017-04-15 21:04 Inserting into vector by reference to element of same vector »
I was wondering if someone more experienced might be able to clarify if this is a buggy operation to do on a vector: std::vector<int> v{1, 2, 3...
(2) odpowiedzi
2017-04-14 15:04 reducing syntax "noise" without using a macro »
I'm trying to find a way of reducing a bit of syntax "noise" without resorting to a macro. For the following code: struct base { base() = delete; };...
(2) odpowiedzi
2017-04-14 13:04 Implicitly deleted default constructor works in C++14 »
I was doing some tests for some code that did not compile, and I discovered that this code: struct A { A(int) {}; virtual void foo() = 0; }; ...
(0) odpowiedzi
2017-04-14 07:04 Why constexpr implicit conversion doesn't always work? »
#include <iostream> struct Index { constexpr operator int() const { return 666; } }; template <int i> void foo() { std::cout &lt...
(0) odpowiedzi
2017-04-13 21:04 Why does llvm::SmallVector split its storage? »
The implementation of llvm::SmallVector<T,N> is split amongst many types: llvm::SmallVectorBase holds 3 void*s for begin, end, and capacity. l...
(1) odpowiedzi
2017-04-13 10:04 Wrapping function arguments? »
Let's suppose that I have this function: void foo (struct1 &v1, struct2 &v2, ..., structn &vn){ //do something with a subset some of t...
(2) odpowiedzi
2017-04-13 05:04 store many of relation 1:1 between various type of objects : decoupling & high performance »
I have 300+ classes. They are related in some ways. For simplicity, all relation are 1:1. Here is a sample diagram. (In real case, there are ...
(5) odpowiedzi