#include #include #include #include #include #include #include #include using namespace boost::multi_index; typedef std::pair int_int_pair; template struct berns_container_impl { typedef std::pair value_type; typedef multi_index_container< value_type, indexed_by< ordered_non_unique< composite_key< value_type, member, member > >, ordered_non_unique< member > > > type; }; template struct berns_container { private: typedef typename berns_container_impl::type impl_type; public: typedef typename impl_type::value_type value_type; typedef typename impl_type::iterator iterator; typedef typename impl_type::const_iterator const_iterator; iterator begin(){return impl.begin();} const_iterator begin()const{return impl.begin();} iterator end(){return impl.end();} const_iterator end()const{return impl.end();} std::pair insert(const value_type& x) { iterator it0=impl.find(boost::make_tuple(x.first)); if(it0!=impl.end()){ typename impl_type::nth_index_iterator<1>::type it1= impl.template get<1>().find(x.second); if(it1!=impl.template get<1>().end()){ return std::make_pair(it0,false); } } return impl.insert(x); } iterator find(const value_type& x)const { return impl.find( boost::make_tuple(boost::cref(x.first),boost::cref(x.second))); } private: impl_type impl; }; int main() { berns_container b; for(;;){ std::cout<<"x y: "; std::string line; std::getline(std::cin,line); if(line.empty())break; std::istringstream issline(line); int x,y; issline>>x>>y; if(!b.insert(std::make_pair(x,y)).second){ std::cout<<"insertion failed"<::iterator it=b.begin();it!=b.end();++it){ std::cout<<"("<first<<","<second<<") "; } std::cout<