मैंने उन मामलों के लिए boost::assign
का उपयोग करना शुरू कर दिया है जिन्हें मैं स्थिर रूप से विशिष्ट मान (ऊपर दिए गए लिंक से उठाए गए उदाहरण) असाइन करना चाहता हूं।
#include <boost/assign/std/vector.hpp>
using namespace boost::assign; // bring 'operator+()' into scope
{
vector<int> values;
values += 1,2,3,4,5,6,7,8,9;
}
आप मानचित्र के लिए boost::assign
का भी उपयोग कर सकते हैं।
#include <boost/assign/list_inserter.hpp>
#include <string>
using boost::assign;
std::map<std::string, int> months;
insert(months)
("january", 31)("february", 28)
("march", 31)("april", 30)
("may", 31)("june", 30)
("july", 31)("august", 31)
("september", 30)("october", 31)
("november", 30)("december", 31);
आप के साथ list_of()
और map_list_of()
#include <boost/assign/list_of.hpp> // for 'list_of()'
#include <list>
#include <stack>
#include <string>
#include <map>
using namespace std;
using namespace boost::assign; // bring 'list_of()' into scope
{
const list<int> primes = list_of(2)(3)(5)(7)(11);
const stack<string> names = list_of("Mr. Foo")("Mr. Bar")
("Mrs. FooBar").to_adapter();
map<int,int> next = map_list_of(1,2)(2,3)(3,4)(4,5)(5,6);
// or we can use 'list_of()' by specifying what type
// the list consists of
next = list_of< pair<int,int> >(6,7)(7,8)(8,9);
}
वहाँ repeat()
, repeat_fun()
के लिए भी कार्य कर रहे हैं प्रत्यक्ष काम की अनुमति देने के कर सकते हैं और range()
जो आप दोहरा मूल्यों या मूल्यों की सीमाएं जोड़ने के लिए अनुमति देता है।
आप भी इस "सी ++" टैग करना होगा। – TonJ
अच्छा बिंदु। किया हुआ। –