std

How to match only those numbers which have an even number of `%`s preceding them?

落花浮王杯 提交于 2019-12-05 07:26:09
I want to catch numbers appearing anywhere in a string, and replace them with "(.+)". But I want to catch only those numbers which have an even number of % s preceding them. No worries if any surrounding chars get caught up: we can use capture groups to filter out the numbers. I'm unable to come up with an ECMAscript regular expression. Here is the playground: abcd %1 %%2 %%%3 %%%%4 efgh abcd%12%%34%%%666%%%%11efgh A successful catch will behave like this: Things I have tried: If you have realised, the third attempt is almost working. The only problems are in the second line of playground.

Why the order is not preserved when printing something, first with cerr and then cout?

女生的网名这么多〃 提交于 2019-12-05 07:01:29
I have g++ version 4.8.4 compiler with Xubuntu 14.04. In the midst of my OpenCV code (written in Eclipse CDT), I wrote the following three lines consecutively: /* Some codes here*/ cerr << "No match found. # of false positives: " << falsePositives << endl; cout << "Press a key to continue..." << endl; waitKey(0); and here is the result: Press a key to continue... No match found. # of false positives: 1 /*there is a blank line*/ Why the order of those two lines changed at the execution time? There is no parallel code at all in the previous lines but they seems to work like parallel (at the same

Best way to delete a std::unique_ptr from a vector with a raw pointer?

一笑奈何 提交于 2019-12-05 06:42:42
So I have a vector like so: std::vector<std::unique_ptr<SomeClass>> myVector; Then I have another vector which contains raw pointers of SomeClass : std::vector<SomeClass*> myOtherVector; If there is an element inside myOtherVector it will also be inside myVector , so I want to go through each element in myOtherVector and remove the same element from myVector . Then clear out the vector. This is what I came up with: for(size_t i = 0; i < myOtherVector.size(); i++) { myVector.erase(std::remove(myVector.begin(), myVector.end(), myOtherVector[i]), myVector.end()); } myOtherVector.clear(); This

What are the default Format Flags (and widths) for double output in a std::stringstream?

跟風遠走 提交于 2019-12-05 05:55:06
问题 What is the default format, when I'm writting a double to a stringstream ? double v = 3.0; std::stringstream ss; ss << v; Where can I find a list of the default format setup for a stringstream ? Is the default format the same for all derived classes of std::istream (within the stdlib)? 回答1: The defaults are setup by std::basic_ios::init and are the same for all streams derived from ios_base . The defaults are: rdbuf() sb tie() 0 rdstate() goodbit if sb is not a null pointer, otherwise badbit.

Thread in C++ in MacOS X

最后都变了- 提交于 2019-12-05 05:44:44
I'm trying to run some code using threads in standard C++ (installed with XCode) in MacOS X Mavericks. But I'm getting some errors. Here's a minimal working example: #include <thread> #include <iostream> void run (int x) { std::cout<<"."; } int main (int argc, char const *argv[]) { std::thread t(run); } The error I'm getting: minimal.cpp:10:17: error: no matching constructor for initialization of 'std::thread' std::thread t(run,0); ^ ~~~~~ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/thread:372:9: note: candidate constructor template not

Is os.popen really deprecated in Python 2.6?

一曲冷凌霜 提交于 2019-12-05 05:36:09
The on-line documentation states that os.popen is now deprecated. All other deprecated functions duly raise a DeprecationWarning. For instance: >>> import os >>> [c.close() for c in os.popen2('ps h -eo pid:1,command')] __main__:1: DeprecationWarning: os.popen2 is deprecated. Use the subprocess module. [None, None] The function os.popen, on the other hand, completes silently: >>>len(list(os.popen('ps h -eo pid:1,command'))) 202 Without raising a warning. Of the three possible scenarios It is expected behaviour that documentation and standard library have different ideas of what is deprecated;

Is it possible to remove queue element by value?

泄露秘密 提交于 2019-12-05 04:59:43
I want to remove element from queue with specific value. How to do such thing? (I am trying to create a concurrent mixture of map and queue and currently I try to implement on this answer ) So I currently have such code: #ifndef CONCURRENT_QUEUED_MAP_H #define CONCURRENT_QUEUED_MAP_H #include <map> #include <deque> #include <boost/thread.hpp> #include <boost/thread/locks.hpp> template <class map_t_1, class map_t_2> class concurrent_queued_map { private: std::map<map_t_1, map_t_2> _ds; std::deque<map_t_1> _queue; mutable boost::mutex mut_; public: concurrent_queued_map() {} map_t_2 get(map_t_1

Searching c++ std vector of structs for struct with matching string

☆樱花仙子☆ 提交于 2019-12-05 04:31:06
I'm sure I'm making this harder than it needs to be. I have a vector... vector<Joints> mJointsVector; ...comprised of structs patterned after the following: struct Joints { string name; float origUpperLimit; float origLowerLimit; }; I'm trying to search mJointsVector with "std::find" to locate an individual joint by its string name - no luck so far, but the examples from the following have helped, at least conceptually: Vectors, structs and std::find Can anyone point me further in the right direction? A straight-forward-approach: struct FindByName { const std::string name; FindByName(const std

Do custom container iterators guarantee ADL to consider namespace std?

让人想犯罪 __ 提交于 2019-12-05 04:18:51
I have no intention of using this in real code. I promise. Does the standard guarantee that std namespace is going to be found when a function argument is of type container::iterator and container::iterator isn't a typedef for a built-in type? For example #include <set> #include <algorithm> int main() { std::set<int> s; find(s.begin(), s.end(), 0); //do I have a guarantee that std::find will be found? } In other words, can the iterator class be defined in such a namespace that std won't be considered by ADL? Thanks in advance. I believe that the answer is no in the most general case, but yes

find an item in a list of pointers

一个人想着一个人 提交于 2019-12-05 04:11:57
I am trying to understand how to find an item in a list of pointers in C++, using std::find If I had for example: std::list<string> words; std::string word_to_be_found; I could just search like this: std::list<string>::iterator matching_iter = std::find(words,begin(), words.end(), word_to_be_found) but what if I have a lsit of pointers? std::list<string *> words; the above syntax will not work anymore. Can I do it some similar way? thanks! You can pass a predicate to the std::find_if function: bool pointee_is_equal(const std::string& s, const std::string* p) { return s == *p; } // ... std: