container_tests.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 815 行 · 第 1/2 页
HPP
815 行
}}inline void test_map_insert(std::map<int, int> c){ using phx::arg_names::arg1; using phx::arg_names::arg2; using phx::arg_names::arg3; typedef std::map<int, int> Map; Map::value_type const value = *c.begin(); Map::iterator c_begin = c.begin(); // wrapper for // iterator insert(iterator where, const value_type& val); Map::iterator it = phx::insert(arg1, arg2, arg3)(c, c_begin, value); if (test(it != c.begin() /*|| *it != *(++it)*/)) { cerr << "Failed " << typeid(Map).name() << " test_map_insert 1\n"; return; } // wrapper for // pair<iterator, bool> insert(const value_type& val); Map::value_type const value2(1400, 2200); std::pair<Map::iterator, bool> result = phx::insert(arg1, arg2)(c, value2); if (test(!result.second)) { cerr << "Failed " << typeid(Map).name() << " test_map_insert 2\n"; return; } // wrapper for // template<class InIt> // void insert(InIt first, InIt last); Map const const_c = build_map(); Map::size_type size = c.size(); phx::insert(arg1, const_c.begin(), const_c.end())(c); if (test(c.size() != size + const_c.size())) { cerr << "Failed " << typeid(Map).name() << " test_map_insert 3\n"; return; }}inline void test_multimap_insert(std::multimap<int, int> c){ using phx::arg_names::arg1; using phx::arg_names::arg2; using phx::arg_names::arg3; typedef std::multimap<int, int> Multimap; Multimap::value_type const value = *c.begin(); Multimap::iterator c_begin = c.begin(); // wrapper for // iterator insert(iterator where, const value_type& val); Multimap::iterator it = phx::insert(arg1, arg2, arg3)(c, c_begin, value); if (test(it != c.begin() || *it != *(++it))) { cerr << "Failed " << typeid(Multimap).name() << " test_multimap_insert 1\n"; return; } // wrapper for // iterator insert(const value_type& val); Multimap::value_type const value2(1400, 2200); it = phx::insert(arg1, arg2)(c, value2); if (test(it == c.end())) { cerr << "Failed " << typeid(Multimap).name() << " test_multimap_insert 2\n"; return; } // wrapper for // template<class InIt> // void insert(InIt first, InIt last); Multimap const const_c = build_multimap(); Multimap::size_type size = c.size(); phx::insert(arg1, const_c.begin(), const_c.end())(c); if (test(c.size() != size + const_c.size())) { cerr << "Failed " << typeid(Multimap).name() << " test_multimap_insert 3\n"; return; }}template <typename Container>void test_key_comp(Container c){ using phx::arg_names::arg1; using phx::key_comp; typename Container::key_compare comp = key_comp(arg1)(c); Container const const_c = c; comp = key_comp(arg1)(const_c);}template <typename Container>void test_max_size(Container c){ using phx::arg_names::arg1; using phx::max_size; Container const const_c = c; typename Container::size_type s1 = max_size(arg1)(c); if (test(s1 != c.max_size())) { cerr << "Failed " << typeid(Container).name() << " test_max_size 1\n"; return; } typename Container::size_type s2 = max_size(arg1)(const_c); if (test(s2 != const_c.max_size())) { cerr << "Failed " << typeid(Container).name() << " test_max_size 2\n"; return; }}template <typename Container>void test_pop_back(Container c){ using phx::arg_names::arg1; using phx::pop_back; Container const const_c = c; typename Container::size_type size = c.size(); pop_back(arg1)(c); if (test(c.size() + 1 != size)) { cerr << "Failed " << typeid(Container).name() << " test_pop_back 1\n"; return; }#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST) pop_back(arg1)(const_c);#endif}template <typename Container>void test_pop_front(Container c){ using phx::arg_names::arg1; using phx::pop_front; Container const const_c = c; typename Container::size_type size = c.size(); pop_front(arg1)(c); if (test(c.size() + 1 != size)) { cerr << "Failed " << typeid(Container).name() << " test_pop_front 1\n"; return; }#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST) pop_front(arg1)(const_c);#endif}template <typename Container>void test_push_back(Container c){ using phx::arg_names::arg1; using phx::arg_names::arg2; using phx::push_back; Container const const_c = c; typename Container::value_type data = *c.begin(); typename Container::size_type size = c.size(); push_back(arg1, arg2)(c, data); if (test(c.size() != size + 1)) { cerr << "Failed " << typeid(Container).name() << " test_push_back 1\n"; return; }#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST) push_back(arg1, arg2)(const_c, data);#endif}template <typename Container>void test_push_front(Container c){ using phx::arg_names::arg1; using phx::arg_names::arg2; using phx::push_front; Container const const_c = c; typename Container::value_type data = *c.begin(); typename Container::size_type size = c.size(); push_front(arg1, arg2)(c, data); if (test(c.size() != size + 1)) { cerr << "Failed " << typeid(Container).name() << " test_push_front 1\n"; return; }#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST) push_front(arg1, arg2)(const_c, data);#endif}template <typename Container>void test_rbegin(Container c){ using phx::arg_names::arg1; using phx::rbegin; typename Container::reverse_iterator it1 = rbegin(arg1)(c); typename Container::reverse_iterator it1_test = c.rbegin(); if (test(it1 != it1_test)) { cerr << "Failed " << typeid(Container).name() << " test_rbegin 1\n"; return; } typename Container::const_reverse_iterator it2 = rbegin(arg1)(c); typename Container::const_reverse_iterator it2_test = c.rbegin(); if (test(it2 != it2_test)) { cerr << "Failed " << typeid(Container).name() << " test_rbegin 2\n"; return; } Container const const_c = c;#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST) // Should not --- does not, Yay! --- compile. typename Container::reverse_iterator it3 = rbegin(arg1)(const_c);#endif typename Container::const_reverse_iterator it4 = rbegin(arg1)(const_c); it2_test = const_c.rbegin(); if (test(it4 != it2_test)) { cerr << "Failed " << typeid(Container).name() << " test_rbegin 4\n"; return; }}template <typename Container>void test_rend(Container c){ using phx::arg_names::arg1; using phx::rend; typename Container::reverse_iterator it1 = rend(arg1)(c); typename Container::reverse_iterator it1_test = c.rend(); if (test(it1 != it1_test)) { cerr << "Failed " << typeid(Container).name() << " test_rend 1\n"; return; } typename Container::const_reverse_iterator it2 = rend(arg1)(c); typename Container::const_reverse_iterator it2_test = c.rend(); if (test(it2 != it2_test)) { cerr << "Failed " << typeid(Container).name() << " test_rend 2\n"; return; } Container const const_c = c;#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST) // Should not --- does not, Yay! --- compile. typename Container::reverse_iterator it3 = rend(arg1)(const_c);#endif typename Container::const_reverse_iterator it4 = rend(arg1)(const_c); it2_test = const_c.rend(); if (test(it4 != it2_test)) { cerr << "Failed " << typeid(Container).name() << " test_rend 4\n"; return; }}template <typename Container>void test_reserve(Container c){ using phx::arg_names::arg1; using phx::reserve; Container const const_c = c; typename Container::size_type count = 2 * c.size(); reserve(arg1, count)(c); if (test(c.capacity() < count)) { cerr << "Failed " << typeid(Container).name() << " test_reserve 1\n"; return; }#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST) reserve(arg1, count)(const_c)(const_c);#endif}template <typename Container>void test_resize(Container c){ using phx::arg_names::arg1; using phx::resize; Container const const_c = c; typename Container::size_type new_size = 2 * c.size(); resize(arg1, new_size)(c); if (test(c.size() != new_size)) { cerr << "Failed " << typeid(Container).name() << " test_resize 1\n"; return; } new_size = 2 * c.size(); typename Container::value_type value = *c.begin(); resize(arg1, new_size, value)(c); if (test(c.size() != new_size)) { cerr << "Failed " << typeid(Container).name() << " test_resize 2\n"; return; }#if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST) new_size = 2 * const_c.size(); resize(arg1, new_size)(const_c); new_size = 2 * const_c.size(); resize(arg1, new_size, value)(const_c);#endif}template <typename Container>void test_size(Container c){ using phx::arg_names::arg1; using phx::size; Container const const_c = c; typename Container::size_type s1 = size(arg1)(c); if (test(s1 != c.size())) { cerr << "Failed " << typeid(Container).name() << " test_size 1\n"; return; } typename Container::size_type s2 = size(arg1)(const_c); if (test(s2 != const_c.size())) { cerr << "Failed " << typeid(Container).name() << " test_size 2\n"; return; }}template <typename Container>void test_splice(Container c){ using phx::arg_names::arg1; using phx::arg_names::arg2; using phx::arg_names::arg3; using phx::arg_names::arg4; using phx::arg_names::arg5; using phx::splice; typename Container::iterator c_end; typename Container::iterator c2_begin; typename Container::iterator c2_end; typename Container::size_type size = c.size(); Container const copy = c; Container const copy2 = build_list(); Container c2 = copy2; size = c.size(); c_end = c.end(); splice(arg1, arg2, arg3)(c, c_end, c2); if (test(c.size() != 2 * size)) { cerr << "Failed " << typeid(Container).name() << " test_splice 1\n"; return; } c = copy; c_end = c.end(); c2 = copy2; c2_begin = c2.begin(); size = c.size() + 1; splice(arg1, arg2, arg3, arg4)(c, c_end, c2, c2_begin); if (test(c.size() != size)) { cerr << "Failed " << typeid(Container).name() << " test_splice 2\n"; return; } c = copy; c_end = c.end(); c2 = copy2; c2_begin = c2.begin(); c2_end = c2.end(); size = c.size() + c2.size(); splice(arg1, arg2, arg3, arg4, arg5)(c, c_end, c2, c2_begin, c2_end); if (test(c.size() != size)) { cerr << "Failed " << typeid(Container).name() << " test_splice 3\n"; return; }}template <typename Container>void test_value_comp(Container c){ using phx::arg_names::arg1; using phx::value_comp; typename Container::value_compare comp = value_comp(arg1)(c); Container const const_c = c; comp = value_comp(arg1)(const_c);}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?