Forward-declaration of std::vector element type for function parameters [duplicate]
This question already has answers here: Why does std::vector work with incomplete types in class definitions? (1 answer) Is a vector with incomplete type allowed if absolutely no member functions are called? If so, since when? (1 answer) Closed 37 mins ago. The following compiles (on GCC) as long as B is fully known (and […]
How to implement an array that can grow up to a limit and never allocates?
I need to implement a container which has most of the functionality of vector
(especially, push_back
, insert
, erase
and sort
) but never allocates memory.
Issue with the STL in C++ cmath
I was compiling the code and found out an issue with the cmath library. I dont know what is wrong it was like ‘x+=pow(n%10,3)’, where the answer should be 152 but it shows 151 This happned while solving the armstrong number problem…
Unable to initialize the size of a vector using scientific notation in C++
I was trying to solve a question on leetcode Count primes, where we need to check whether a number is prime, for all numbers less than a given number. The easiest way I knew was to precompute a boolean vector using the sieve of Eratosthenes containing true if the number is prime, and false if it isn’t.
How to inplace initialize std::array<std::pair>?
I am trying to create a static map for where the type of the key is an enum, and the values and keys are stored inside an std::array.
Custom Comparator for a Priority Queue in C++
I am really confused on how the comparators for pq work in cpp. so my understanding of arrays are if we have something like
std::map/std::set and equal_range, what’s the reasoning here?
I just noticed that std::map
and std::set
have the member function equal_range
returning an iterator range of values for a certain key. How does this make sense when a map and a set are always ordered key/value (as in a single key for a single value, or both combined) containers.
How can I get data from binary file?
I get ‘binary file’ made with write() member function.
Do std::(unordered_)map and std::(unordered_)set share code?
Let’s say that I care about binary size, I already use std::map
, and I need a set. Instead of using std::set<T>
, I could use std::map<T, bool>
. Will that help, or is common code already used under the hood?