std

How to initialize std stack with std vector?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 18:19:08
问题 I need to put an std::vector into an std::stack . Here is my method so far(I am building a card game) : void CardStack::initializeCardStack(std::vector<Card> & p_cardVector) { m_cardStack = std::stack<Card>(); //code that should initialize m_cardStack with p_cardVector } Note : I cannot change my method signature because it is a imposed by a teacher... Do I have to iterate over the whole vector ? What is the most efficient way to do this ? The documentation. I have tried Jens answer but it

Xcode cannot find cstddef

試著忘記壹切 提交于 2019-12-10 17:54:15
问题 Xcode (iOS) cannot for some reason find cstddef for a library I'm using (Boost). Does any one know how to fix this? I am compiling under Mac OS X 10.8 with Xcode 4.6 回答1: You should make your project all Objective-C++, renaming all the files to * .mm extension. 来源: https://stackoverflow.com/questions/17304545/xcode-cannot-find-cstddef

How does begin() know which return type to return (const or non-const)?

青春壹個敷衍的年華 提交于 2019-12-10 17:49:36
问题 This works perfectly : list<int> l; list<int>::const_iterator it; it = l.begin(); list<int>::iterator it2; it2 = l.begin(); What I don't get is how the list "knows" that it must return the iterator begin() version or the const_iterator begin() const one. I'm trying to implement iterators for my container (a trie) and I'm running into this problem. Isn't C++ supposed not to handle differentiation by return type (except when using weird tricks)? Here is some code and the compiler error I get :

Comparing two sets of std::weak_ptr

南笙酒味 提交于 2019-12-10 17:44:49
问题 I am trying to compare two sets of C++11 weak_ptr using GCC 4.7.2. The code below shows the smallest possible sample reproducing the error: std::set<std::weak_ptr<int>, std::owner_less<std::weak_ptr<int> > > set1; std::set<std::weak_ptr<int>, std::owner_less<std::weak_ptr<int> > > set2; bool result = (set1 == set2); Trying to compile the above results in a long list of errors, of which the following is the first actual error: /usr/include/c++/4.7/bits/stl_algobase.h:791:6: error: no match for

c++ std regex question mark issue

淺唱寂寞╮ 提交于 2019-12-10 17:44:23
问题 I'm having troubles with std regex. I can't make the question mark quantifier work. The call to regex_match will always return 0. I also tried with {0,1} which doesn't behave like I expected either: it behaves like a + quantifier. Here is my code : #include <iostream> #include <regex> using namespace std; int main(int argc, char **argv){ regex e1("ab?c"); cout << regex_match("ac", e1) << endl; // expected : 1, output 0 cout << regex_match("abc", e1) << endl; // expected : 1, output 0 cout <<

C++ Add months to chrono::system_clock::time_point

左心房为你撑大大i 提交于 2019-12-10 16:17:11
问题 How can I add months to a chrono::system_clock::time_point value? Thank you! 回答1: Overview This is a very interesting question with several answers. The "correct" answer is something you must decide for your specific application. With months, you can choose to do either chronological computations or calendrical computations . A chronological computation deals with regular units of time points and time durations, such as hours, minutes and seconds. A calendrical computation deals with

Alternative to stdext::hash_map for performance reasons

ぐ巨炮叔叔 提交于 2019-12-10 16:09:46
问题 I'm working on a high performance application where all calls must be justified. I have a map that is used once in the beginning of each transaction to do a lookup that I would like to improve upon. The map is loaded at startup and does not change after that. The key in the map below is an std::string but it can it changed to a char array if needed. C or C++ as a solution is fine. typedef stdext::hash_map<std:string, int> symbols_t; Does anyone know of any other solutions that would eliminate

Gradle compileKotlin includeRuntime not adding runtime to jar

痴心易碎 提交于 2019-12-10 15:38:22
问题 I have a Kotlin Gradle project, and I would like to include Kotlin's runtime and stdlib in the jar file. I'm currently using this, but it's not including the runtime or stdlib when I build the project using the build.gradle configuration. compileKotlin { kotlinOptions { includeRuntime = true noStdlib = false } } This is the Gradle code I'm using to include the runtime/stdlib in the jar, but it isn't working like I expect it to. Here's the full build.gradle file for some context: https:/

std:sort vs inserting into an std::set

主宰稳场 提交于 2019-12-10 15:26:52
问题 I am reading some line segments from cin. Each line segment is represented by a start and end point. 2D. X and Y. The input is not sorted. It is in random order. (Update:But I need them sorted first by X and then by Y) I can read in all the segments, store them in a vector and then call std::sort. On the other hand, I can create an empty std::set and insert each segment as it arrives. The set will automatically maintain sorted order. Which of the two approaches is more efficient? Update: The

STL containers' range insert functions returning void under c++11?

狂风中的少年 提交于 2019-12-10 15:09:00
问题 Just learning c++, so I may not be understanding this correctly, but I've only read that the range insert function returns an iterator under the new standard (C++ Primer 5th Ed, cplusplus.com, cppreference.com, and various answers suggesting to use it to maintain iterator validity). From cppreference.com: template< class InputIt > iterator insert( const_iterator pos, InputIt first, InputIt last ); However, every version of Cygwin GCC and MinGW that I've tried has returned void using -std=c+