All Questions
56,758 questions
2 votes
1 answer
187 views
Are the iterators of `map<key, value, greater<>>` and `map<key, value, less<>>` guaranteed to be the same type?
I have 2 maps using BidBook = std::map<float, int, std::greater<>>; // price -> qty using AskBook = std::map<float, int, std::less<>>; I have a struct that contain iterator ...
16 votes
2 answers
719 views
Parsing of small floats with std::istream
I have a program that reads the coordinates of some points from a text file using std::istringstream, and then it verifies the correctness of parsing by calling stream's operator bool(). In general it ...
1 vote
1 answer
141 views
Are the map/multimap iterators interchangeable?
In the code below I'm defining a map and a multimap. Then I'm defining four iterators assigning them values from these containers: std::map<int, double> m; std::multimap<int, double> mm; ...
0 votes
0 answers
65 views
Commands out of sync MySQL error - possible missing commit [duplicate]
I'm trying to run: BEGIN TRANSACTION; CREATE TABLE IF NOT EXIST abc(); SELECT( IF( ( SELECT 1 FROM information_schema.statistics WHERE index_name = 'abc_x' AND table_name = 'abc' ) > 0, SELECT 0, ...
15 votes
4 answers
1k views
What is the size of std::array<T,0>?
Unlike C array, std::array is allowed to have zero length. But the current implementations differ in how std::array<T,0> is implemented, in particular the sizes of the object are different. This ...
3 votes
1 answer
321 views
How strong is the as-if rule in C++
As an exercice and side project I have started to write a runtime SIMD library in C++ that wraps around the intrinsics and that builds an expression tree. Each possible node in a tree must contain an ...
0 votes
1 answer
105 views
Undefined reference to header only library [duplicate]
Goal Use concise makefile with organized directory structure. In particular, I don't want to have to edit the makefile to manage dependencies with every new source addition. The assumed directory ...
6 votes
2 answers
209 views
C++ pointers and concurrency
I need some help for understanding general basics of shared resource access in C++ multithreading. When I need some variable that must be accessible for several threads, I declare it as atomic, or ...
8 votes
2 answers
332 views
When creating a C style header, is it ABI compatible to switch between enum and enum class?
I'm creating a dll + supporting header for a C library; which then has a C++ implementation. The header file exposes an enum, returned by some of the functions. Is this example guaranteed to produce ...
8 votes
2 answers
346 views
Move constructor called with copy elision?
The following code prints "move constructor" with c++11/c++14 with -fno-elide-constructors. However, with c++17/c++20 and -fno-elide-constructors, no "move constructor" prints. Why ...
1 vote
1 answer
128 views
Correct way to set ready flag for std::condition_variable [duplicate]
I have two threads where one thread needs to wait for the other thread to complete its task. To solve this problem I decided to use std::condition_variable. My question is, should the thread that is ...
1 vote
1 answer
169 views
Why is it impossible to cast ref-unqualified member function pointer to a ref-qualified member function pointer?
This code is rejected by all compilers I could test it on, so I suppose it is ill-formed according to the standard. struct X { void f(); }; void (X::*fptr)() & = &X::f; // ERROR Here we ...
2 votes
2 answers
125 views
How to partially specialize for a type nested in a template?
I have a template struct with a nested class, eg. template <typename T> struct example { struct type { }; }; template <typename T> using example_t = typename example<T>::type; ...
-1 votes
2 answers
127 views
Reinterpret_cast array of bits as byte [closed]
I want to cast an array of bits into a byte, it works by using a loop and bitshift, but I think it would be cost inefective if run repeatedly (I might be wrong). So I wanted to use a pointer with ...
0 votes
1 answer
112 views
std::unordered_map data member with const key inside const method not compiling
Here is a small piece of code: class myClass { public: void myMethod() const { for (const auto& entity : myList) { auto iter = myMap.find(&entity); } } private: std::list&...