STL

homeend

New member
STL

הי הי אני מנסה להשתמש ב set בפונקציה insert אני מנסה להכניס שני איטרטורים של set set<int> s1,s2; s2.insert(s1.begin(),s1.end()) ;//does not compile יש למשהוא רעיון תודה מראש
 

the new L

New member
לפי מה

שראיתי ב header של set, הפונקציה insert מקבלת פרמטרים שהם value_type *. כלומר קוד כזה יעבוד למשל:
set<int> s; int i[] = {1,2,3,4,5}; s.insert(i,i+5);​
 

the new L

New member
ודרך לעשות

את מה שאתה רוצה:
#include <iostream> #include <algorithm> #include <set> using namespace std; template <class T> class Insertor { public: Insertor(set<T> &insertSet) : m_Set(insertSet) { } void operator() (const T &t) { m_Set.insert(t); } private: set<T> &m_Set; }; int main() { set<int> s1,s2; s1.insert(1); s1.insert(2); for_each(s1.begin(),s1.end(),Insertor<int>(s2)); return 0; }​
 

the new L

New member
אופס

תתעלם מה iostream בהתחלה, לא באמת צריך אותו מן הסתם... :)
 
למעלה