Is begin() == end() for any empty() vector?

Yes, that’s what the standard requires it to be for empty() for any container. ยง 23.2.1 Table 96 of the C++11 standard says: +———-+—————+———————-+ |Expression| Return Type | Operational Semantics| |———-|—————|———————-| |a.empty() |Convertible |a.begin() == a.end() | | |to bool | | | | | | +————————————————-+

Correct way to work with vector of arrays

You cannot store arrays in a vector or any other container. The type of the elements to be stored in a container (called the container’s value type) must be both copy constructible and assignable. Arrays are neither. You can, however, use an array class template, like the one provided by Boost, TR1, and C++0x: std::vector<std::array<double, … Read more

Java 8 times faster with arrays than std::vector in C++. What did I do wrong?

Yep, the cache in the c++ version takes a hammering. It seems the JIT is better equipped to handle this. If you change the outer for in isUpdateNeeded() to shorter snippets. The difference goes away. The sample below produces a 4x speedup. void isUpdateNeeded() { for (int i = 0; i < numberOfCells; ++i) { … Read more

std::dynarray vs std::vector

So what are the benefits and the usage of std::dynarray, when we can use std::vector which is more dynamic (Re-sizable)? dynarray is smaller and simpler than vector, because it doesn’t need to manage separate size and capacity values, and it doesn’t need to store an allocator. However the main performance benefit is intended to come … Read more

How to shuffle a std::vector?

From C++11 onwards, you should prefer: #include <algorithm> #include <random> auto rng = std::default_random_engine {}; std::shuffle(std::begin(cards_), std::end(cards_), rng); Live example on Coliru Make sure to reuse the same instance of rng throughout multiple calls to std::shuffle if you intend to generate different permutations every time! Moreover, if you want your program to create different sequences … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)