vector
#include <iostream> #include <boost/container/vector.hpp> #include <boost/container/map.hpp> #include <boost/fusion/include/std_pair.hpp> #include <boost/fusion/include/io.hpp> namespace bstd = boost::container; using namespace boost::fusion::operators; int main() { { bstd::vector<std::pair<int, std::string>> v; v.emplace_back(3, "Alice"); // v.push_back(std::make_pair(3, "Alice"))の代わり v.emplace_back(1, "Bob"); v.emplace_back(4, "Carol"); for (const auto& x : v) { std::cout << x << std::endl; } } std::cout << "--------" << std::endl; { bstd::map<int, std::string> m; m.emplace(3, "Alice"); // m.insert(std::make_pair(3, "Alice"))の代わり m.emplace(1, "Bob"); m.emplace(4, "Carol"); for (const auto& x : m) { std::cout << x << std::endl; } } }
(3 Alice) (1 Bob) (4 Carol) -------- (1 Bob) (3 Alice) (4 Carol)
すっきり。