int main() { { typedef std::unordered_multiset<int> C; typedef int P; P a[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() == 7); assert(c.size() == 6); assert(std::distance(c.begin(), c.end()) == c.size()); assert(std::distance(c.cbegin(), c.cend()) == c.size()); C::iterator i = c.begin(); assert(*i == 1); *i = 2; } { typedef std::unordered_multiset<int> C; typedef int P; P a[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; const C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() == 7); assert(c.size() == 6); assert(std::distance(c.begin(), c.end()) == c.size()); assert(std::distance(c.cbegin(), c.cend()) == c.size()); } }
int main() { { typedef double T; typedef std::array<T, 3> C; C c = {1, 2, 3.5}; assert(c.size() == 3); assert(c.max_size() == 3); assert(!c.empty()); } { typedef double T; typedef std::array<T, 0> C; C c = {}; assert(c.size() == 0); assert(c.max_size() == 0); assert(c.empty()); } #ifndef _LIBCPP_HAS_NO_CONSTEXPR { typedef double T; typedef std::array<T, 3> C; constexpr C c = {1, 2, 3.5}; static_assert(c.size() == 3, ""); static_assert(c.max_size() == 3, ""); static_assert(!c.empty(), ""); } { typedef double T; typedef std::array<T, 0> C; constexpr C c = {}; static_assert(c.size() == 0, ""); static_assert(c.max_size() == 0, ""); static_assert(c.empty(), ""); } #endif }
int main() { { typedef std::unordered_map<int, std::string> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.size() == 4); c.at(1) = "ONE"; assert(c.at(1) == "ONE"); #ifndef TEST_HAS_NO_EXCEPTIONS try { c.at(11) = "eleven"; assert(false); } catch (std::out_of_range&) { } assert(c.size() == 4); #endif } { typedef std::unordered_map<int, std::string> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; const C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.size() == 4); assert(c.at(1) == "one"); #ifndef TEST_HAS_NO_EXCEPTIONS try { c.at(11); assert(false); } catch (std::out_of_range&) { } assert(c.size() == 4); #endif } #if TEST_STD_VER >= 11 { typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>, min_allocator<std::pair<const int, std::string>>> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.size() == 4); c.at(1) = "ONE"; assert(c.at(1) == "ONE"); #ifndef TEST_HAS_NO_EXCEPTIONS try { c.at(11) = "eleven"; assert(false); } catch (std::out_of_range&) { } assert(c.size() == 4); #endif } { typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>, min_allocator<std::pair<const int, std::string>>> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; const C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.size() == 4); assert(c.at(1) == "one"); #ifndef TEST_HAS_NO_EXCEPTIONS try { c.at(11); assert(false); } catch (std::out_of_range&) { } assert(c.size() == 4); #endif } #endif }
int main() { { typedef std::unordered_map<int, std::string> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 5); assert(c.size() == 4); assert(std::distance(c.begin(), c.end()) == c.size()); assert(std::distance(c.cbegin(), c.cend()) == c.size()); C::iterator i; } { typedef std::unordered_map<int, std::string> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; const C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 5); assert(c.size() == 4); assert(std::distance(c.begin(), c.end()) == c.size()); assert(std::distance(c.cbegin(), c.cend()) == c.size()); C::const_iterator i; } #if __cplusplus >= 201103L { typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>, min_allocator<std::pair<const int, std::string>>> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 5); assert(c.size() == 4); assert(std::distance(c.begin(), c.end()) == c.size()); assert(std::distance(c.cbegin(), c.cend()) == c.size()); C::iterator i; } { typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>, min_allocator<std::pair<const int, std::string>>> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; const C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 5); assert(c.size() == 4); assert(std::distance(c.begin(), c.end()) == c.size()); assert(std::distance(c.cbegin(), c.cend()) == c.size()); C::const_iterator i; } #endif #if _LIBCPP_STD_VER > 11 { // N3644 testing typedef std::unordered_map<int,double> C; C::iterator ii1{}, ii2{}; C::iterator ii4 = ii1; C::const_iterator cii{}; assert ( ii1 == ii2 ); assert ( ii1 == ii4 ); assert ( ii1 == cii ); assert ( !(ii1 != ii2 )); assert ( !(ii1 != cii )); } #endif }
typedef C::value_type V; C m( { {1, 1}, {1, 1.5}, {1, 2}, {2, 1}, {2, 1.5}, {2, 2}, {3, 1}, {3, 1.5}, {3, 2} }, Cmp(4), A(5) ); REQUIRE(m.size() == 9); REQUIRE(distance(m.begin(), m.end()) == 9); C::const_iterator i = m.cbegin(); REQUIRE(*i == V(1, 1)); REQUIRE(*++i == V(1, 1.5)); REQUIRE(*++i == V(1, 2)); REQUIRE(*++i == V(2, 1)); REQUIRE(*++i == V(2, 1.5)); REQUIRE(*++i == V(2, 2)); REQUIRE(*++i == V(3, 1)); REQUIRE(*++i == V(3, 1.5)); REQUIRE(*++i == V(3, 2)); REQUIRE(m.key_comp() == Cmp(4)); REQUIRE(m.get_allocator() == A(5)); } #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
void ptr_map_test() { using namespace boost; BOOST_TEST_MESSAGE( "starting associative container test" ); enum { max_cnt = 10, size = 100 }; C c; BOOST_CHECK( c.size() == 0 ); const C c2( c.begin(), c.end() ); BOOST_CHECK( c.size() == c2.size() ); C c3; BOOST_TEST_MESSAGE( "finished construction test" ); BOOST_DEDUCED_TYPENAME C::allocator_type alloc = c.get_allocator(); BOOST_DEDUCED_TYPENAME C::iterator i = c.begin(); BOOST_DEDUCED_TYPENAME C::const_iterator ci = c2.begin(); BOOST_DEDUCED_TYPENAME C::iterator i2 = c.end(); hide_warning(i2); BOOST_DEDUCED_TYPENAME C::const_iterator ci2 = c2.begin(); hide_warning(ci2); ci = c.cbegin(); ci = c.cend(); BOOST_DEDUCED_TYPENAME C::key_type a_key; BOOST_TEST_MESSAGE( "finished iterator test" ); BOOST_DEDUCED_TYPENAME C::size_type s = c.size(); BOOST_DEDUCED_TYPENAME C::size_type s2 = c.max_size(); hide_warning(s2); BOOST_CHECK_EQUAL( c.size(), s ); bool b = c.empty(); hide_warning(b); BOOST_TEST_MESSAGE( "finished accessors test" ); a_key = get_next_key( a_key ); c.insert( a_key, new T ); a_key = get_next_key( a_key ); c.insert( a_key, new T ); c3.insert( c.begin(), c.end() ); c.insert( c3 ); c.erase( c.begin() ); BOOST_CHECK( c3.end() == c3.erase( boost::make_iterator_range(c3) ) ); c3.erase( a_key ); BOOST_CHECK( c3.empty() ); c.swap( c3 ); swap(c,c3); swap(c3,c); BOOST_CHECK( !c3.empty() ); c3.clear(); BOOST_CHECK( c3.empty() ); BOOST_TEST_MESSAGE( "finished modifiers test" ); a_key = get_next_key( a_key ); c.insert( a_key, new T ); a_key = get_next_key( a_key ); #ifndef BOOST_NO_AUTO_PTR c.insert( a_key, std::auto_ptr<T>( new T ) ); #endif #ifndef BOOST_NO_CXX11_SMART_PTR c.insert( a_key, std::unique_ptr<T>( new T ) ); #endif typename C::auto_type ptr2 = c.release( c.begin() ); #ifndef BOOST_NO_AUTO_PTR std::auto_ptr<C> ap = c.release(); #else std::unique_ptr<C> up = c.release(); #endif c = c2.clone(); BOOST_TEST_MESSAGE( "finished release/clone test" ); a_key = get_next_key( a_key ); c3.insert( a_key, new T ); a_key = get_next_key( a_key ); c3.insert( a_key, new T ); c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3 ); c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3.end(), c3 ); BOOST_CHECK( c3.empty() ); BOOST_CHECK( !c.empty() ); c3. BOOST_NESTED_TEMPLATE transfer<C>( c ); BOOST_CHECK( !c3.empty() ); BOOST_CHECK( c.empty() ); #ifdef BOOST_NO_SFINAE #else c. BOOST_NESTED_TEMPLATE transfer<C>( make_iterator_range(c3), c3 ); BOOST_CHECK( !c.empty() ); BOOST_CHECK( c3.empty() ); c3. BOOST_NESTED_TEMPLATE transfer<C>(c); #endif BOOST_TEST_MESSAGE( "finished transfer test" ); BOOST_CHECK( !c3.empty() ); c3.replace( c3.begin(), new T ); #ifndef BOOST_NO_AUTO_PTR c3.replace( c3.begin(), std::auto_ptr<T>( new T ) ); #endif #ifndef BOOST_NO_CXX11_SMART_PTR c3.replace( c3.begin(), std::unique_ptr<T>( new T ) ); #endif BOOST_TEST_MESSAGE( "finished set/map interface test" ); // @todo: make macro with algorithms so that the right erase() is called. // c.unique(); // c.unique( std::not_equal_to<T>() ); // c.remove( T() ); // c.remove_if( std::binder1st< std::equal_to<T> >( T() ) ); sub_range<C> sub; sub_range<const C> csub; i = c.find( get_next_key( a_key ) ); ci = c2.find( get_next_key( a_key ) ); c2.count( get_next_key( a_key ) ); sub = c.equal_range( get_next_key( a_key ) ); csub = c2.equal_range( get_next_key( a_key ) ); try { c.at( get_next_key( a_key ) ); } catch( const bad_ptr_container_operation& ) { } try { c2.at( get_next_key( a_key ) ); } catch( const bad_ptr_container_operation& ) { } BOOST_TEST_MESSAGE( "finished algorithms interface test" ); typename C::iterator it = c.begin(), e = c.end(); for( ; it != e; ++it ) { std::cout << "\n mapped value = " << *it->second << " key = " << it->first; //std::cout << "\n mapped value = " << it.value() << " key = " << it.key(); } BOOST_TEST_MESSAGE( "finished iterator test" ); a_key = get_next_key( a_key ); c.insert( a_key, new T ); c.erase( a_key ); c.erase( a_key ); }
size_t size() const { return collection.size(); }
void main() { { typedef unordered_multimap<int, std::string> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; C c(a, a + sizeof(a)/sizeof(a[0])); ///assert(c.bucket_count() >= 7); assert(c.size() == 6); assert((size_t)std::distance(c.begin(), c.end()) == c.size()); assert((size_t)std::distance(c.cbegin(), c.cend()) == c.size()); C::iterator i; i = c.begin(); i->second = "ONE"; assert(i->second == "ONE"); } { typedef unordered_multimap<int, std::string> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; const C c(a, a + sizeof(a)/sizeof(a[0])); ///assert(c.bucket_count() >= 7); assert(c.size() == 6); assert((size_t)std::distance(c.begin(), c.end()) == c.size()); assert((size_t)std::distance(c.cbegin(), c.cend()) == c.size()); C::const_iterator i; } //#if __cplusplus >= 201103L #ifdef LIBCPP_TEST_MIN_ALLOCATOR { typedef unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>, min_allocator<std::pair<const int, std::string>>> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 7); assert(c.size() == 6); assert((size_t)std::distance(c.begin(), c.end()) == c.size()); assert((size_t)std::distance(c.cbegin(), c.cend()) == c.size()); C::iterator i; i = c.begin(); i->second = "ONE"; assert(i->second == "ONE"); } { typedef unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>, min_allocator<std::pair<const int, std::string>>> C; typedef std::pair<int, std::string> P; P a[] = { P(1, "one"), P(2, "two"), P(3, "three"), P(4, "four"), P(1, "four"), P(2, "four"), }; const C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 7); assert(c.size() == 6); assert((size_t)std::distance(c.begin(), c.end()) == c.size()); assert((size_t)std::distance(c.cbegin(), c.cend()) == c.size()); C::const_iterator i; } #endif //#if _LIBCPP_STD_VER > 11 { // N3644 testing typedef unordered_multimap<int,double> C; C::iterator ii1{}, ii2{}; C::iterator ii4 = ii1; C::const_iterator cii{}; assert ( ii1 == ii2 ); assert ( ii1 == ii4 ); assert (!(ii1 != ii2 )); assert ( (ii1 == cii )); assert ( (cii == ii1 )); assert (!(ii1 != cii )); assert (!(cii != ii1 )); } //#endif }
void reversible_container_test() { using namespace boost; BOOST_TEST_MESSAGE( "starting reversible container test" ); enum { max_cnt = 10, size = 100 }; C c; set_capacity<C>()( c ); BOOST_CHECK( c.size() == 0 ); c.push_back( new T ); BOOST_CHECK( c.size() == 1 ); const C c2_dummy( c.begin(), c.end() ); BOOST_CHECK_EQUAL( c2_dummy.size(), c.size() ); const C c2( c.clone() ); BOOST_CHECK_EQUAL( c2.size(), c.size() ); C c3( c.begin(), c.end() ); set_capacity<C>()( c3 ); BOOST_CHECK_EQUAL( c.size(), c3.size() ); c.assign( c3.begin(), c3.end() ); BOOST_CHECK_EQUAL( c.size(), c3.size() ); c.assign( c3 ); set_capacity<C>()( c ); BOOST_TEST_MESSAGE( "finished construction test" ); C a_copy( c ); BOOST_CHECK_EQUAL( a_copy.size(), c.size() ); a_copy = a_copy; BOOST_CHECK_EQUAL( a_copy.size(), c.size() ); a_copy.clear(); a_copy = a_copy; BOOST_CHECK( a_copy.empty() ); BOOST_CHECK( !c.empty() ); BOOST_TEST_MESSAGE( "finished copying test" ); BOOST_DEDUCED_TYPENAME C::allocator_type alloc = c.get_allocator(); hide_warning(alloc); BOOST_DEDUCED_TYPENAME C::iterator i = c.begin(); BOOST_DEDUCED_TYPENAME C::const_iterator ci = c2.begin(); BOOST_DEDUCED_TYPENAME C::iterator i2 = c.end(); BOOST_DEDUCED_TYPENAME C::const_iterator ci2 = c2.begin(); BOOST_DEDUCED_TYPENAME C::reverse_iterator ri = c.rbegin(); BOOST_DEDUCED_TYPENAME C::const_reverse_iterator cri = c2.rbegin(); BOOST_DEDUCED_TYPENAME C::reverse_iterator rv2 = c.rend(); BOOST_DEDUCED_TYPENAME C::const_reverse_iterator cvr2 = c2.rend(); i = c.rbegin().base(); ci = c2.rbegin().base(); i = c.rend().base(); ci = c2.rend().base(); BOOST_CHECK_EQUAL( std::distance( c.rbegin(), c.rend() ), std::distance( c.begin(), c.end() ) ); BOOST_TEST_MESSAGE( "finished iterator test" ); BOOST_DEDUCED_TYPENAME C::size_type s = c.size(); hide_warning(s); BOOST_DEDUCED_TYPENAME C::size_type s2 = c.max_size(); hide_warning(s2); c.push_back( new T ); c.push_back( std::auto_ptr<T>( new T ) ); bool b = c.empty(); BOOST_CHECK( !c.empty() ); b = is_null( c.begin() ); BOOST_CHECK( b == false ); BOOST_DEDUCED_TYPENAME C::reference r = c.front(); hide_warning(r); BOOST_DEDUCED_TYPENAME C::const_reference cr = c2.front(); hide_warning(cr); BOOST_DEDUCED_TYPENAME C::reference r2 = c.back(); hide_warning(r2); BOOST_DEDUCED_TYPENAME C::const_reference cr2 = c2.back(); hide_warning(cr2); BOOST_TEST_MESSAGE( "finished accessors test" ); c.push_back( new T ); BOOST_CHECK_EQUAL( c.size(), 4u ); c.pop_back(); BOOST_CHECK( !c.empty() ); c.insert( c.end(), new T ); std::auto_ptr<T> ap(new T); c.insert( c.end(), ap ); BOOST_CHECK_EQUAL( c.size(), 5u ); #if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) #else c.insert( c.end(), c3 ); #endif c3.insert( c3.end(), c.begin(), c.end() ); c.erase( c.begin() ); c3.erase( c3.begin(), c3.end() ); c3.erase( boost::make_iterator_range(c3) ); BOOST_CHECK( c3.empty() ); BOOST_CHECK( !c.empty() ); c.swap( c3 ); BOOST_CHECK( !c3.empty() ); c3.clear(); BOOST_CHECK( c3.empty() ); C c4; c4.swap(c3); #ifdef BOOST_NO_SFINAE #else swap(c4,c3); #endif BOOST_TEST_MESSAGE( "finished modifiers test" ); c.push_back( new T ); c.push_back( new T ); c.push_back( new T ); typedef BOOST_DEDUCED_TYPENAME C::auto_type auto_type; #ifdef BOOST_NO_SFINAE #else auto_type ptr = c.release( c.begin() ); #endif std::auto_ptr<C> ap2 = c.release(); c = c2.clone(); BOOST_CHECK( !c.empty() ); auto_type ptr2 = c.replace( c.begin(), new T ); ptr2 = c.replace( c.begin(), std::auto_ptr<T>( new T ) ); BOOST_TEST_MESSAGE( "finished release/clone/replace test" ); c3.push_back( new T ); c3.push_back( new T ); c3.push_back( new T ); c. BOOST_NESTED_TEMPLATE transfer<C>( c.begin(), c3.begin(), c3 ); c. BOOST_NESTED_TEMPLATE transfer<C>( c.end(), c3.begin(), c3.end(), c3 ); #ifdef BOOST_NO_SFINAE #else c. BOOST_NESTED_TEMPLATE transfer<C>( c.end(), boost::make_iterator_range( c3 ), c3 ); BOOST_CHECK( c3.empty() ); BOOST_CHECK( !c.empty() ); #endif c3. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c ); BOOST_CHECK( !c3.empty() ); BOOST_CHECK( c.empty() ); BOOST_TEST_MESSAGE( "finished transfer test" ); c3.resize( 0u ); BOOST_CHECK( c3.empty() ); c3.resize( 10u ); BOOST_CHECK_EQUAL( c3.size(), 10u ); c3.resize( 12u, &*c3.begin() ); BOOST_CHECK_EQUAL( c3.size(), 12u ); BOOST_TEST_MESSAGE( "finished resize test" ); }
int main() { { typedef std::unordered_multiset<int> C; typedef int P; P a[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 7); assert(c.size() == 6); assert(std::distance(c.begin(), c.end()) == c.size()); assert(std::distance(c.cbegin(), c.cend()) == c.size()); C::iterator i; } { typedef std::unordered_multiset<int> C; typedef int P; P a[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; const C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 7); assert(c.size() == 6); assert(std::distance(c.begin(), c.end()) == c.size()); assert(std::distance(c.cbegin(), c.cend()) == c.size()); C::const_iterator i; } #if __cplusplus >= 201103L { typedef std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C; typedef int P; P a[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 7); assert(c.size() == 6); assert(std::distance(c.begin(), c.end()) == c.size()); assert(std::distance(c.cbegin(), c.cend()) == c.size()); C::iterator i; } { typedef std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C; typedef int P; P a[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; const C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 7); assert(c.size() == 6); assert(std::distance(c.begin(), c.end()) == c.size()); assert(std::distance(c.cbegin(), c.cend()) == c.size()); C::const_iterator i; } #endif #if _LIBCPP_STD_VER > 11 { // N3644 testing typedef std::unordered_multiset<int> C; C::iterator ii1{}, ii2{}; C::iterator ii4 = ii1; C::const_iterator cii{}; assert ( ii1 == ii2 ); assert ( ii1 == ii4 ); assert ( ii1 == cii ); assert ( !(ii1 != ii2 )); assert ( !(ii1 != cii )); } #endif }
void main() { { typedef unordered_set<int> C; typedef int P; P a[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 5); assert(c.size() == 4); assert((size_t)std::distance(c.begin(), c.end()) == c.size()); assert((size_t)std::distance(c.cbegin(), c.cend()) == c.size()); C::iterator i; } { typedef unordered_set<int> C; typedef int P; P a[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; const C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 5); assert(c.size() == 4); assert((size_t)std::distance(c.begin(), c.end()) == c.size()); assert((size_t)std::distance(c.cbegin(), c.cend()) == c.size()); C::const_iterator i; } //#if __cplusplus >= 201103L #ifdef LIBCPP_TEST_MIN_ALLOCATOR { typedef unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C; typedef int P; P a[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 5); assert(c.size() == 4); assert((size_t)std::distance(c.begin(), c.end()) == c.size()); assert((size_t)std::distance(c.cbegin(), c.cend()) == c.size()); C::iterator i; } { typedef unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C; typedef int P; P a[] = { P(1), P(2), P(3), P(4), P(1), P(2) }; const C c(a, a + sizeof(a)/sizeof(a[0])); assert(c.bucket_count() >= 5); assert(c.size() == 4); assert((size_t)std::distance(c.begin(), c.end()) == c.size()); assert((size_t)std::distance(c.cbegin(), c.cend()) == c.size()); C::const_iterator i; } #endif //#if _LIBCPP_STD_VER > 11 { // N3644 testing typedef unordered_set<int> C; C::iterator ii1{}, ii2{}; C::iterator ii4 = ii1; C::const_iterator cii{}; assert ( ii1 == ii2 ); assert ( ii1 == ii4 ); assert (!(ii1 != ii2 )); assert ( (ii1 == cii )); assert ( (cii == ii1 )); assert (!(ii1 != cii )); assert (!(cii != ii1 )); } //#endif }
void ptr_set_test() { using namespace boost; BOOST_MESSAGE( "starting associative container test" ); enum { max_cnt = 10, size = 100 }; C c; BOOST_CHECK( c.size() == 0 ); c.insert( c.end(), new T ); c.insert( c.end(), new T ); const C c2( c.begin(), c.end() ); BOOST_CHECK( c.size() == c2.size() ); C c3; BOOST_MESSAGE( "finished construction test" ); C a_copy( c ); BOOST_CHECK_EQUAL( a_copy.size(), c.size() ); a_copy = a_copy; BOOST_CHECK_EQUAL( a_copy.size(), c.size() ); c.clear(); a_copy = c; a_copy = a_copy; BOOST_CHECK( a_copy.empty() ); BOOST_MESSAGE( "finished copying test" ); BOOST_DEDUCED_TYPENAME C::allocator_type alloc = c.get_allocator(); BOOST_DEDUCED_TYPENAME C::iterator i = c.begin(); BOOST_DEDUCED_TYPENAME C::const_iterator ci = c2.begin(); ci = c.cbegin(); ci = c.cend(); BOOST_DEDUCED_TYPENAME C::iterator i2 = c.end(); BOOST_DEDUCED_TYPENAME C::const_iterator ci2 = c2.begin(); BOOST_MESSAGE( "finished iterator test" ); BOOST_DEDUCED_TYPENAME C::size_type s = c.size(); BOOST_DEDUCED_TYPENAME C::size_type s2 = c.max_size(); hide_warning(s2); BOOST_CHECK_EQUAL( c.size(), s ); bool b = c.empty(); hide_warning(b); BOOST_MESSAGE( "finished accessors test" ); T* t = new T; c.insert( c.end(), t ); c.insert( c.end(), std::auto_ptr<T>( new T ) ); c.insert( new T ); c.insert( std::auto_ptr<T>( new T ) ); c3.insert( c.begin(), c.end() ); c.erase( c.begin() ); c3.erase( c3.begin(), c3.end() ); t = new T; c.insert( new T ); c.erase( *t ); delete t; BOOST_CHECK( c3.empty() ); c.swap( c3 ); BOOST_CHECK( !c3.empty() ); BOOST_CHECK( c.empty() ); c3.clear(); // // remark: we cannot pass c3 directly as it would // extract const iterators ... and the // current standard does not allow erase() // to be given const iterators // c3.erase( boost::make_iterator_range(c3) ); BOOST_CHECK( c3.empty() ); BOOST_MESSAGE( "finished modifiers test" ); c.insert( c.end(), new T ); typename C::auto_type ptr2 = c.release( c.begin() ); std::auto_ptr<C> ap = c.release(); c = c2.clone(); BOOST_MESSAGE( "finished release/clone test" ); c3.insert( new T ); c3.insert( new T ); BOOST_CHECK_EQUAL( c3.size(), 2u ); #if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) #else c3.insert( make_iterator_range( c ) ); // BOOST_CHECK_EQUAL( c3.size(), 4u ); #endif c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3 ); BOOST_CHECK( c3.empty() == false ); c.clear(); unsigned long c3size = c3.size(); hide_warning( c3size ); unsigned long num = c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3.end(), c3 ); BOOST_CHECK( num > 0 ); BOOST_CHECK_EQUAL( num, c.size() ); BOOST_CHECK( c3.empty() ); BOOST_CHECK( !c.empty() ); c3. BOOST_NESTED_TEMPLATE transfer<C>( c ); BOOST_CHECK( !c3.empty() ); BOOST_CHECK( c.empty() ); #ifdef BOOST_NO_SFINAE #else c. BOOST_NESTED_TEMPLATE transfer<C>( make_iterator_range( c3 ), c3 ); BOOST_CHECK( !c.empty() ); BOOST_CHECK( c3.empty() ); #endif BOOST_MESSAGE( "finished transfer test" ); C c4; c4.swap(c3); swap(c4,c3); BOOST_MESSAGE( "finished set/map interface test" ); sub_range<C> sub; sub_range<const C> csub; t = new T; i = c.find( *t ); ci = c2.find( *t ); c2.count( *t ); test_algorithms<T,Ordered>()( c, c2 ); sub = c.equal_range( *t ); csub = c2.equal_range( *t ); delete t; BOOST_MESSAGE( "finished algorithms interface test" ); }
void ptr_set_test() { using namespace boost; BOOST_MESSAGE( "starting associative container test" ); enum { max_cnt = 10, size = 100 }; C c; BOOST_CHECK( c.size() == 0 ); const C c2( c.begin(), c.end() ); BOOST_CHECK( c.size() == c2.size() ); C c3; BOOST_MESSAGE( "finished construction test" ); BOOST_DEDUCED_TYPENAME C::allocator_type alloc = c.get_allocator(); BOOST_DEDUCED_TYPENAME C::iterator i = c.begin(); BOOST_DEDUCED_TYPENAME C::const_iterator ci = c2.begin(); BOOST_DEDUCED_TYPENAME C::iterator i2 = c.end(); BOOST_DEDUCED_TYPENAME C::const_iterator ci2 = c2.begin(); BOOST_DEDUCED_TYPENAME C::reverse_iterator ri = c.rbegin(); BOOST_DEDUCED_TYPENAME C::const_reverse_iterator cri = c2.rbegin(); BOOST_DEDUCED_TYPENAME C::reverse_iterator rv2 = c.rend(); BOOST_DEDUCED_TYPENAME C::const_reverse_iterator cvr2 = c2.rend(); BOOST_MESSAGE( "finished iterator test" ); BOOST_DEDUCED_TYPENAME C::size_type s = c.size(); BOOST_DEDUCED_TYPENAME C::size_type s2 = c.max_size(); hide_warning(s2); BOOST_CHECK_EQUAL( c.size(), s ); bool b = c.empty(); hide_warning(b); BOOST_MESSAGE( "finished accessors test" ); T* t = new T; c.insert( c.end(), t ); c.insert( c.end(), std::auto_ptr<T>( new T ) ); c.insert( new T ); c.insert( std::auto_ptr<T>( new T ) ); c3.insert( c.begin(), c.end() ); c.erase( c.begin() ); c3.erase( c3.begin(), c3.end() ); BOOST_CHECK( c3.empty() ); c.swap( c3 ); BOOST_CHECK( !c3.empty() ); c3.clear(); BOOST_CHECK( c3.empty() ); BOOST_MESSAGE( "finished modifiers test" ); c.insert( c.end(), new T ); typename C::auto_type ptr2 = c.release( c.begin() ); std::auto_ptr<C> ap = c.release(); c = c2.clone(); BOOST_MESSAGE( "finished release/clone test" ); c3.insert( new T ); c3.insert( new T ); BOOST_CHECK_EQUAL( c3.size(), 2u ); #if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) #else c3.insert( make_iterator_range( c ) ); // BOOST_CHECK_EQUAL( c3.size(), 4u ); #endif c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3 ); BOOST_CHECK( c3.empty() == false ); c. BOOST_NESTED_TEMPLATE transfer<C>( c3.begin(), c3.end(), c3 ); BOOST_CHECK( c3.empty() ); BOOST_CHECK( !c.empty() ); c3. BOOST_NESTED_TEMPLATE transfer<C>( c ); BOOST_CHECK( !c3.empty() ); BOOST_CHECK( c.empty() ); #ifdef BOOST_NO_SFINAE #else c. BOOST_NESTED_TEMPLATE transfer<C>( make_iterator_range( c3 ), c3 ); BOOST_CHECK( !c.empty() ); BOOST_CHECK( c3.empty() ); #endif BOOST_MESSAGE( "finished transfer test" ); C c4; c4.swap(c3); swap(c4,c3); BOOST_MESSAGE( "finished set/map interface test" ); sub_range<C> sub; sub_range<const C> csub; t = new T; i = c.find( *t ); ci = c2.find( *t ); c2.count( *t ); i = c.lower_bound( *t ); ci = c2.lower_bound( *t ); i = c.upper_bound( *t ); ci = c2.upper_bound( *t ); sub = c.equal_range( *t ); csub = c2.equal_range( *t ); delete t; BOOST_MESSAGE( "finished algorithms interface test" ); }