Quantcast
Channel: My Filter (2) - Stack Exchange
Browsing all 102 articles
Browse latest View live

insert vs emplace when dealing with rvalues – stackoverflow.com

std::string myString;std::unordered_set<std::string> mySet;mySet.insert(std::move(myString));mySet.emplace(std::move(myString)); // this is an example, in reality you can't move twiceI ...

View Article



STL priority_queue using reinsertion for key decrease not working –...

I'm trying to implement an A*-like algorithm, and I am having trouble implementing key decrease using the STL priority_queue container. I am trying to reinsert elements into the queue when I decrease...

View Article

Non-programmatically affect the returned value of...

I have a parallel c++ algorithm implemented using STL algorithms and the std::execution::parallel_policy policy.Now, I would like to be able to benchmark how much performance varies as the number of ...

View Article

How to efficiently copy from gsl::span to std::vector? – stackoverflow.com

To copy from a C++20 std::span into an std::vector I can simply do the following:void WriteBuffer(std::vector<std::byte>& destData, const std::span<const std::byte>& srcData){ ...

View Article

C++ generic overload of operator

I mean to write a generic overload of operator<< to print STL containers.I put together code below.Whenever operator<< involves a string, it produces a compilation error ambiguous ...

View Article


C++ - how to find all subranges which are sandwiched between two values using...

I have an array with integer values in domain [0,258)I want to find all sub ranges in domain [0,256) which are sandwiched between 256 and 257.I.e. all sub-ranges of the form {256,...,257} where ...

View Article

Error in custom comparator for multimap stl c++11 – stackoverflow.com

I am trying to run the following code where I create the multimap structure with key and value as pair of two integer values. I want the stucture to be sorted (without using explicit sorting ...

View Article

How to access a particular set element using iterator? – stackoverflow.com

Need a simple bi-directional dictionary. I understand there might be better solutions but I want to understand where I am wrong with this one. The algorithm is based of three things:it needs to be ...

View Article


Let CMake link against specific version of libstdc++– stackoverflow.com

I'm working on a fresh installed Debian-12 at where only the version 11/12 of gcc/g++ can be installed against the official apt repository.But my producing target app must be compiled with g++-9, so ...

View Article


How to correctly upgrade STL from the source of GCC – stackoverflow.com

I built gcc/g++ 10.5.0 from source, because I guessed that v10.5.0 is more stable than v10.2.1 that is the latest version I can get from the official apt repository of Debian-11.The making scripts ...

View Article

How to use a std:vector with custom objects with ChaiScript? – stackoverflow.com

I'm trying to expose a STL vector of custom objects to chaiscript but no matter what I do, it just gives an exceptionHere's the smallest example I could think of. it just passes std::vector<...

View Article

How to call std::for_each on a vector of std::function without lambda? –...

I want to callback functions, that are stored in a vector, e.g.,std::vector<std::function<void()> xs{};std::for_each(xs.begin(), xs.end(), [](auto& func) { func(); });But how do I ...

View Article

Even though I inserted 20 (distinct) elements into my std::set, it only has a...

typedef vector<int> vec;struct classcomp { bool operator() (const vec& vec1, const vec& vec2) const{ if (vec1[0] > vec2[0]){ return true; } ...

View Article


Converting values inside nested stl containers – stackoverflow.com

My whole point is that I have astruct S { double x, y; // some code defining properties and operations on such pairs. // ... // ... operator std::pair<double, double>(){ return ...

View Article

Why does GCC copy object for each comparison in `std::ranges::max`? –...

Consider the following example (Godbolt):#include <vector>#include <iostream>#include <ranges>#include <algorithm>struct A{ A() {} A( const A& ) { std::cout ...

View Article


Why do std::ranges::set_difference, std::ranges::set_intersection do not work...

I know the reason is that those algorithms are specified to require sorted ranges as input, so unordered_set will not work, but I wonder why those algorithms were not specified to understand unordered...

View Article

Why does this usage of std::move and std::list with a custom view type cause...

I was reading §5.1.7.2 of Rainer Grimm's book C++20: Get the Details about defining one's own view type when I decided to modify the provided code sample to see if it would work with a std::list. The...

View Article


warning STL4016: std::shared_ptr::unique() is deprecated in C++17, how to...

I have the following usage of .unique()void pixmappool::flush() { auto it = _pool.begin(); while (it != _pool.end()) { if (it->second.unique()) { it = _pool.erase(it); } else { ...

View Article

C++ Vector Declaration Syntax – stackoverflow.com

Confused why vector declaration syntax is different than any other data structure. For example an Array.vector<int> myvectorWhereas an array can be declared as suchint arr[] = {1, 2}

View Article

make_move_iterator for data member and const: how make it failed? –...

Here is example:#include <vector>#include <iterator>class Foo {public: void combine(std::vector<std::vector<float>> &all_data) const { ...

View Article
Browsing all 102 articles
Browse latest View live




Latest Images