stl

possible std::async implementation bug Windows

橙三吉。 提交于 2020-01-02 12:14:21
问题 It seems like there is a bug in the windows implementation of std::async. Under heavy load (on the order of 1000 threads launched async per second), async tasks are never scheduled and waiting on the returned futures leads to deadlocks. See this piece of code (modified with launch policy deferred instead of async): BundlingChunk(size_t numberOfInputs, Bundler* parent, ChunkIdType chunkId) : m_numberOfInputs(numberOfInputs), m_parent(parent), m_chunkId(chunkId) { const BundlerChunkDescription&

possible std::async implementation bug Windows

你离开我真会死。 提交于 2020-01-02 12:14:10
问题 It seems like there is a bug in the windows implementation of std::async. Under heavy load (on the order of 1000 threads launched async per second), async tasks are never scheduled and waiting on the returned futures leads to deadlocks. See this piece of code (modified with launch policy deferred instead of async): BundlingChunk(size_t numberOfInputs, Bundler* parent, ChunkIdType chunkId) : m_numberOfInputs(numberOfInputs), m_parent(parent), m_chunkId(chunkId) { const BundlerChunkDescription&

How to build OpenCV for Android using libc++ STL library?

↘锁芯ラ 提交于 2020-01-02 11:29:52
问题 I would like to build a OpenCV from source using a libc++ STL library, instead of default GNU STL. LibC++ offers better C++11 and C++14 support. Is it possible to do that? 回答1: I've tested this with OpenCV 2.4.7 and Android NDK r10d. First, you need to download OpenCV source. Unpack the source and replace the platforms/android/android.toolchain.cmake with version that suppports libc++. Now, open modules/core/include/opencv2/core/operations.hpp and change line 69 from (defined __GNUC__ &&

STL - does every compiler implement it differently?

点点圈 提交于 2020-01-02 09:36:24
问题 It was said to me that the standard template library is differently implemented by every compiler, is this correct? How can computational complexity (both in time and space) be observed if (for instance) the set container is implemented with a linked list rather than a red-black tree? Did I miss something? 回答1: First things first, you probably mean the C++ standard library , not STL. The STL was a library written before C++ was standardised that heavily influenced the C++ standard library.

Populate a vector<int> from integers in a char *

[亡魂溺海] 提交于 2020-01-02 08:38:22
问题 char *values = " 3 1 4 15"; vector<int> array; I want to populate the array with the values, 3,1,4,15 Is there a slick way to do it with the stl copy algorithm? 回答1: Indeed there is: std::istringstream iss(values); std::copy(std::istream_iterator<int>(iss), std::istream_iterator<int>(), std::back_inserter(array)); 来源: https://stackoverflow.com/questions/372453/populate-a-vectorint-from-integers-in-a-char

handle empty string case extracting a string from std::istream

无人久伴 提交于 2020-01-02 08:15:20
问题 Using the following code to extract a string from a std::istream : #include <sstream> #include <iostream> void parse(std::istream & is, std::string & out) { is >> out; } int main(int argc, char** argv) { if (argc>1) { std::istringstream is(argv[1]); std::string out("__INIT__"); std::cout << "good:" << is.good() << " fail:"<< is.fail() << " eof:"<< is.eof() << " in_avail:"<< is.rdbuf()->in_avail() << " value:" << out << std::endl; parse(is, out); std::cout << "good:" << is.good() << " fail:"<<

find a pair in a STL list where only first element is known

十年热恋 提交于 2020-01-02 07:05:14
问题 assumend I have a (filled) list std::list<std::pair<int,otherobject>> myList; and want to find() the first element within this list, where int has a specific value - how can I do that? To explain it a bit further: I want to append these pairs to the list with an int that identifies otherobject but is not unique. The order where these int/otherobject pairs arrive has to be kept. When an int is found during access to elements of this list the first occurence of that int has to be given back

STL iterator with custom template

倖福魔咒の 提交于 2020-01-02 05:39:05
问题 i have the following template method, template <class T> void Class::setData( vector<T> data ) { vector<T>::iterator it; } and i'm getting the following compilation error ( XCode/gcc ) error: expected `;' before 'it' i found someone else with a similar problem here (read down to see it's the same even though it starts out with a different issue) but they seem to have resolved by updating Visual Studio. This makes me guess that it is a compiler issue and that it should compile, is that correct

C++ for-each statement triggers “vector iterators incompatible” assertion failure: this->_Getcont() == 0

孤街醉人 提交于 2020-01-02 05:33:05
问题 This is with Visual Studio 2012. static void func( ..., const std::vector<std::string> &opt_extra_args_strs, ...) { // THIS ASSERTS: "vector iterators incompatible" for (const std::string &arg_str : opt_extra_args_strs) { ... body does not modify opt_extra_args_strs // BUT THIS WORKS: for (size_t a_ix = 0; a_ix < opt_extra_args_strs.size(); a_ix++) { const std::string &arg_str = opt_extra_args_strs[a_ix]; } I am not modifying the vector at all in the loop body, and in fact, the assertion

Using push_back on a vector<vector<string> > [closed]

﹥>﹥吖頭↗ 提交于 2020-01-02 05:03:55
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I'm somewhat embarrassed that such a simple problem has stymied me, but after a few hours of fruitless googling, I'm still stuck. To simplify my problem,