Boost.Foreach
Chapter 7. Boost.Foreach - 1.47.0
ãã¯ãã§å®ç¾©ãããforeachã
(C+11ã§Range-based for loopããµãã¼ããããã®ã§å¿
è¦ãªããªã£ã¡ããã¾ããã)
é
åãSTLã³ã³ãããstd::pairã¤ãã¬ã¼ã¿ãNull-terminated string(char and wchar_t)ãåããã
â»ãã ãããã¯ããªã®ã§åã«,ãå«ã¾ãã¦ãã¨ãã¡
å¤ã«åºãããtypedefãã
boost_foreach_TEST.cpp
#include<iostream> #include<vector> #include<map> #include<string> #include<algorithm> #include<boost/foreach.hpp> int main(){ int a[] = { 0, 2, 4, 6, 8 }; int size = sizeof(a)/sizeof(a[0]); std::vector<int> b(a,a+size); std::map<std::string, std::string> MS; MS["MS-06FZ"] = "ã¶ã¯IIæ¹"; MS["MS-18E"] = " ã±ã³ããã¡ã¼"; MS["MSM-03C"] = "ãã¤ã´ãã°"; std::cout<<"a = "; BOOST_FOREACH(int e, a){ std::cout<< e << " "; } std::cout << std::endl; std::cout<<"b = "; BOOST_FOREACH(int e, b) std::cout<< e << " "; std::cout << std::endl; std::cout << "MS" <<std::endl; //ãã¯ããªã®ã§åã«,ãå«ã¾ãã¦ãã¨ãã¡ //BOOST_FOREACH(std::pair<std::string, std::string> e, MS) std::cout << e.first <<" "<<e.second <<std::endl; std::pair<std::string, std::string> ele; BOOST_FOREACH(ele, MS) std::cout<<ele.first <<" "<<ele.second <<std::endl; std::cout << "typedefãã¦ããï½"<<std::endl; typedef std::pair<std::string, std::string> e_t; BOOST_FOREACH(e_t e, MS) std::cout << e.first <<" "<<e.second <<std::endl; return 0; }
çµæ
a = 0 2 4 6 8 b = 0 2 4 6 8 MS MS-06FZ ã¶ã¯IIæ¹ MS-18E ã±ã³ããã¡ã¼ MSM-03C ãã¤ã´ãã° typedefãã¦ããï½ MS-06FZ ã¶ã¯IIæ¹ MS-18E ã±ã³ããã¡ã¼ MSM-03C ãã¤ã´ãã°