Data dodania Pytanie
2017-03-04 18:03 Is it allowed to call destructor explicitly followed by placement new on a variable with fixed lifetime? »
I know that calling destructor explicitly can lead to undefined behavior because of double destructor calling, like here: #include <vector> in...
(2) odpowiedzi
2017-03-04 12:03 How to efficiently count the highest power of 2 that is less than or equal to a given number? »
I came up with three solutions so far: The extremely inefficient standard library pow and log2 functions: int_fast16_t powlog(uint_fast16_t n) { r...
(6) odpowiedzi
2017-03-04 08:03 Why is my C++ disk write test much slower than a simply file copy using bash? »
Using below program I try to test how fast I can write to disk using std::ofstream. I achieve around 300 MiB/s when writing a 1 GiB file. However, ...
(4) odpowiedzi
2017-03-03 22:03 Why is `std::array` slower than `std::vector`? »
Note: This has only been confirmed in an online IDE, tests on my own laptop do not confirm this. Let us test the performance of the two containers wi...
(0) odpowiedzi
2017-03-03 20:03 Double brace initialization »
Which constructor should be called in the following code and why? struct S { int i; S() = default; S(void *) : i{1} { ; } }; S s{{}}; ...
(1) odpowiedzi
2017-03-03 15:03 Check if one set of types is a subset of the other »
How can one check if one parameter pack (interpreted as a set) is a subset of another one? So far I only have the frame (using std::tuple), but no fu...
(9) odpowiedzi
2017-03-03 14:03 Why does "std::begin()" always return "const_iterator" in such a case? »
#include <vector> #include <iostream> using namespace std; int main() { vector<int> coll; decltype(std::begin(std::declva...
(2) odpowiedzi
2017-03-02 22:03 Surprising behavior of literal type at runtime »
I'm a bit perplexed by the behavior of this code compiled with clang 3.9: struct A { constexpr A() = default; A(const A&) = delete; c...
(2) odpowiedzi
2017-03-02 21:03 Why are these matrix transposition times so counter-intuitive? »
The following example code generates a matrix of size N, and transposes it SAMPLES number of times. When N = 512 the average execution time of the tra...
(1) odpowiedzi
2017-03-02 16:03 Why is std::fill(0) slower than std::fill(1)? »
I have observed on a system that std::fill on a large std::vector<int> was significantly and consistently slower when setting a constant value 0...
(1) odpowiedzi
2017-03-01 21:03 What is the function execution order in code like foo(bar())? »
Assume we have code like this in C or C++: foo(bar()); What is the function execution order in this case? Is it required that bar() is called fir...
(6) odpowiedzi
2017-03-01 18:03 Possible C/C++ compiler bug in Visual Studio 2013 »
The following C or C++ code should have as output "11,11,11," however using Visual Studio Professional 2013 (Version 12.0.40629.00 Update 5) the outpu...
(1) odpowiedzi
2017-03-01 14:03 Why does std::set not have a "contains" member function? »
I'm heavily using std::set<int> and often I simply need to check if such a set contains a number or not. I'd find it natural to write: if (mys...
(7) odpowiedzi
2017-03-01 10:03 Call C++ class methods or function from Java on android without recreating class/variable on every call »
I have a pretty complex NLP code written on C++ and now I want to use it from my android app. My idea is to build app using client-server architecture...
(1) odpowiedzi
2017-03-01 02:03 Placement-new address alignment »
According to https://isocpp.org/wiki/faq/dtors#placement-new the address passed into placement-new has to be properly aligned. But the example it give...
(3) odpowiedzi
2017-03-01 01:03 How does std::set comparator function work? »
Currently working on an algorithm problems using set. set<string> mySet; mySet.insert("(())()"); mySet.insert("()()()"); //print mySet: (())(...
(4) odpowiedzi
2017-02-28 19:02 I just can not understand DR 712 »
DR 712 was responsible for the change in the wording of [basic.def.odr]/2 in C++11 to the current wording today, in [basic.def.odr]2 and 3. But I'm st...
(2) odpowiedzi
2017-02-28 15:02 casting uint32_t to uint64_t results in different value? »
Using Visual Studio 2015 C++, 14.0.25431.01 Update 3. I have unexpected behavior in my code. Compile and run with 64bit, Release: #include <iostre...
(2) odpowiedzi
2017-02-28 00:02 Packing and de-interleaving two __m256 registers »
I have a row-wise array of floats (~20 cols x ~1M rows) from which I need to extract two columns at a time into two __m256 registers. ...a0.........b...
(3) odpowiedzi
2017-02-27 21:02 C++ Transform a std::tuple<A, A, A...> to a std::vector or std::deque »
In the simple parser library I am writing, the results of multiple parsers is combined using std::tuple_cat. But when applying a parser that returns t...
(2) odpowiedzi
2017-02-27 17:02 `type *var = (int)0`, legal or not? »
The following example: char *var = (int)0; Compiles on gcc and cl.exe, but causes an error in clang: cannot initialize a variable of type 'char...
(1) odpowiedzi
2017-02-27 15:02 Compare two sets of types for equality »
How can one check if two parameter packs are the same, ignoring their internal order? So far I only have the frame (using std::tuple), but no functio...
(4) odpowiedzi
2017-02-27 14:02 Avoiding virtual function calls in a computational graph »
I'm using a DAG (directed acyclic graph) to represent and evaluate expressions; each node represents an operation (+, -, /, *, accumulate, etc...) and...
(1) odpowiedzi
2017-02-26 17:02 Possible race condition in std::condition_variable? »
I've looked into the VC++ implementation of std::condition_variable(lock,pred), basically, it looks like this: template<class _Predicate> ...
(1) odpowiedzi
2017-02-26 15:02 C++ String to lowercase with custom locale »
I've been trying to call std::tolower() with a different locale but it seems that something is going wrong. My code is as follows: int main() { s...
(2) odpowiedzi
2017-02-26 07:02 C++ template class taking both const and non-const types »
I would like to have a wrapper class that keeps and returns a pointer to some element of a wrapped container. It looks like: template <typename T&...
(1) odpowiedzi
2017-02-25 22:02 Why capturing by reference in lambda doesn't change the type of the variables? »
I thought that capturing by reference changes the types of the variables. Lets consider the following example: #include <cassert> #include <...
(2) odpowiedzi
2017-02-25 15:02 Dealing with heavy profiling of execution times in C++ »
I'm currently working on a scientific computing project involving huge data and complex algorithms, so I need to do a lot of code profiling. I'm curre...
(2) odpowiedzi
2017-02-25 12:02 C++ using passed function »
I have two functions one of them takes a function as an argument this works just fine, but I want to call this passed function in my second one. clas...
(1) odpowiedzi
2017-02-25 01:02 printf the value of %n in the same call - senseless? »
I can't find out the intention of the following part of printf specification at cppreference.com: There is a sequence point after the action of ea...
(3) odpowiedzi
2017-02-24 16:02 Why does glm::vec represent vec values as unions? »
I was looking at vec4 glm's source code implementation, and I was wondering why they represent vector values with a union, instead of primitive data t...
(2) odpowiedzi
2017-02-24 13:02 Is the lifetime of a reference extended? »
I'd like to pass a reference into a function. This code does not work, as I'd expect: struct A { }; void foo(A& a) { // do something with a ...
(3) odpowiedzi
2017-02-24 09:02 Does vector know to reserve first when initializing by a pair of iterators? »
Consider the following code. struct MyData{ MyData(const BYTE* pData, size_t uSize) : bucket_(pData, pData + uSize) {} std...
(2) odpowiedzi
2017-02-23 17:02 integral_constants in ternary operator »
MSVC and clang/gcc disagree on whether two different integral constants can be used in a ternary operator (and as a consequence whether they have a co...
(2) odpowiedzi
2017-02-23 16:02 `std::complex<T>[n]` and `T[n*2]` type aliasing »
Since C++11 std::complex<T>[n] is guaranteed to be aliasable as T[n*2], with well defined values. Which is exactly what one would expect for any...
(3) odpowiedzi