If I want to use std::any I can use it with RTTI switched off. The following example compiles and runs as expected also with -fno-rtti with gcc.
To fill STL containers with values that depend on their index, I usually write like the code below. Is there any way to do the same without declaring the index?
I want to initialize a container with pointers to objects. I currently have a loop like this:Which C++ operation (i.e. similar to std::transform) is the right to replace this loop and initialize a container with n newly created objects?
Given a std::vector, whose size and capacity can be arbitrary, what's the best practice to change its size to 0 and capacity to at least N(a given number)?
Please take a look at the std::advance function. According to cppreference the complexity is:Linear. However, if InputIt additionally meets the requirements of RandomAccessIterator, complexity is constant.
c++11 includes the algorithm partition_point in the STL. However for all the cases I have tried it gives the same answer as lower_bound. The only difference being the convenient T& value parameter. Did I miss something or are these two functions doing more or less the same thing?
I am reading a code sample from cppreference:I am not sure why q2 does not need to be initialized? I.e. Instead of having
While explaining move operations on objects with a colleague, I basically said that move operations should not throw exceptions in a container because if the move operation fails, then there is no way to bring back the original object reliably. Thinking about this more, I'm wondering if that is not...
With my compiler (1, 2, 3) work but (4, 5) don't. The compiler complains about its incapability to choose the overload for case 5.
The algorithm std::includes takes two sorted ranges and checks whether set2 is in set1 (i.e. if each element of set2 is included in set1)?