Data dodania Pytanie
2017-04-28 07:04 Ambigous constructor call with list-initialization »
struct A { A(int) {} }; struct B { B(A) {} }; int main() { B b({0}); } The construction of b gives the following errors: In function ...
(5) odpowiedzi
2017-04-27 12:04 Are all integer values perfectly represented as doubles? »
My question is whether all integer values are guaranteed to have a perfect double representation. Consider the following code sample that prints "Sa...
(5) odpowiedzi
2017-04-27 12:04 adapter pattern : support underlying data that can be const or non-const, elegantly »
How to make an adapter class to support both const and non-const underlying data appropriately? Concrete Example RigidBody is a class describing phy...
(3) odpowiedzi
2017-04-27 10:04 GCC fails to optimize aligned std::array like C array »
Here's some code which GCC 6 and 7 fail to optimize when using std::array: #include <array> static constexpr size_t my_elements = 8; class Fo...
(1) odpowiedzi
2017-04-26 18:04 How to properly use exceptions with LLVM JIT? »
Going through llvm tutorial I've implemented JIT and found that my REPL unexpectedly fails with segfault. Debugger shows that operator throw causes th...
(0) odpowiedzi
2017-04-26 12:04 How to use this macro to test if memory is aligned? »
I'm a simd beginner, I've read this article about the topic (since I'm using a AVX2-compatible machine). Now, I've read in this question to check if...
(1) odpowiedzi
2017-04-26 05:04 Accessing a moved std::string in a new thread »
Consider the case below The name string is moved as an argument to the thread. void start(std::string&& name) { t = std::thread{&...
(2) odpowiedzi
2017-04-25 21:04 Matching alias template as template argument »
Consider the following code: #include <type_traits> template<template<class...> class T, class... U> struct is_specialization_of :...
(2) odpowiedzi
2017-04-25 17:04 std::thread: How to wait (join) for any of the given threads to complete? »
For example, I have two threads, t1 and t2. I want to wait for t1 or t2 to finish. Is this possible? If I have a series of threads, say, a std::vecto...
(4) odpowiedzi
2017-04-25 10:04 Duplicate code using c++11 »
I'm currently working on a project and I have the following issue. I have a C++ method that I want to work in two different ways : void MyFunction()...
(6) odpowiedzi
2017-04-25 02:04 C++ matrix computation efficiency »
We are trying to optimize our C++ code and the we have the following matrix computation (using the Eigen library) #include<Eigen/Dense> int ma...
(1) odpowiedzi
2017-04-24 20:04 Which should I prefer for a constant within a function: constexpr const or enum? »
I'm used to definition my constants with enum { my_const = 123; }, since in classes, using static constexpr requires some code outside of the class de...
(2) odpowiedzi
2017-04-24 11:04 Dangling reference in inner lambda »
I have an inner lambda that uses one of the referenced variables of the outer lambda like this: int x=0; auto outer=[&](){ return [&](){ ...
(3) odpowiedzi
2017-04-24 08:04 Why is this diamond class inheritance output not what I expect? »
Consider: #include <iostream> using namespace std; class A {// base class private: int data; public: A(int data = 0) { t...
(3) odpowiedzi
2017-04-23 22:04 C++ macro only works when preprocessed to a file »
I am trying to create a matching mechanism for the new std::optional<T> in C++. I've written the following macro: #define EXPAND(x) x #define C...
(1) odpowiedzi
2017-04-23 19:04 How can I modify the std::launch policy afterwards for std::async? »
Suppose I want to use std::async for parallelism in my c++ code to run a computationally heavy function func. Now since it is a heavy function, we mig...
(1) odpowiedzi
2017-04-23 18:04 Does declaring a variable inside a loop body have any disadvantages? »
Suppose we have a loop that iterates many times: for (int i=0; i < 1000000; ++i) { int s = 100; s += i; cout << s; } We are only usi...
(3) odpowiedzi
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