Index: libcxx/test/std/containers/associative/map/map.ops/count.pass.cpp =================================================================== --- libcxx/test/std/containers/associative/map/map.ops/count.pass.cpp +++ libcxx/test/std/containers/associative/map/map.ops/count.pass.cpp @@ -20,89 +20,22 @@ #include "private_constructor.h" #include "is_transparent.h" -int main(int, char**) -{ - { - typedef std::pair V; - typedef std::map M; - { - typedef M::size_type R; - V ar[] = - { - V(5, 5), - V(6, 6), - V(7, 7), - V(8, 8), - V(9, 9), - V(10, 10), - V(11, 11), - V(12, 12) - }; - const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); - R r = m.count(5); - assert(r == 1); - r = m.count(6); - assert(r == 1); - r = m.count(7); - assert(r == 1); - r = m.count(8); - assert(r == 1); - r = m.count(9); - assert(r == 1); - r = m.count(10); - assert(r == 1); - r = m.count(11); - assert(r == 1); - r = m.count(12); - assert(r == 1); - r = m.count(4); - assert(r == 0); - } - } #if TEST_STD_VER >= 11 + template + struct FinalCompare final { - typedef std::pair V; - typedef std::map, min_allocator> M; - { - typedef M::size_type R; - V ar[] = + bool operator()(const T& x, const T& y) const { - V(5, 5), - V(6, 6), - V(7, 7), - V(8, 8), - V(9, 9), - V(10, 10), - V(11, 11), - V(12, 12) - }; - const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); - R r = m.count(5); - assert(r == 1); - r = m.count(6); - assert(r == 1); - r = m.count(7); - assert(r == 1); - r = m.count(8); - assert(r == 1); - r = m.count(9); - assert(r == 1); - r = m.count(10); - assert(r == 1); - r = m.count(11); - assert(r == 1); - r = m.count(12); - assert(r == 1); - r = m.count(4); - assert(r == 0); - } - } + return x < y; + } + }; #endif -#if TEST_STD_VER > 11 - { - typedef std::pair V; - typedef std::map> M; - typedef M::size_type R; + +template +void test() +{ + typedef typename Map::value_type V; + typedef typename Map::size_type R; V ar[] = { @@ -115,81 +48,62 @@ V(11, 11), V(12, 12) }; - const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); - R r = m.count(5); - assert(r == 1); - r = m.count(6); - assert(r == 1); - r = m.count(7); - assert(r == 1); - r = m.count(8); - assert(r == 1); - r = m.count(9); - assert(r == 1); - r = m.count(10); - assert(r == 1); - r = m.count(11); - assert(r == 1); - r = m.count(12); - assert(r == 1); - r = m.count(4); - assert(r == 0); - - r = m.count(C2Int(5)); - assert(r == 1); - r = m.count(C2Int(6)); - assert(r == 1); - r = m.count(C2Int(7)); - assert(r == 1); - r = m.count(C2Int(8)); - assert(r == 1); - r = m.count(C2Int(9)); - assert(r == 1); - r = m.count(C2Int(10)); - assert(r == 1); - r = m.count(C2Int(11)); - assert(r == 1); - r = m.count(C2Int(12)); - assert(r == 1); - r = m.count(C2Int(4)); - assert(r == 0); + + const Map m(ar, ar + sizeof(ar) / sizeof(ar[0])); + + for (int i = 0; i < 5; ++i) + { + R r = m.count(i); + assert(r == 0); } + for (int i = 5; i < 13; ++i) { - typedef PrivateConstructor PC; - typedef std::map> M; - typedef M::size_type R; - - M m; - m [ PC::make(5) ] = 5; - m [ PC::make(6) ] = 6; - m [ PC::make(7) ] = 7; - m [ PC::make(8) ] = 8; - m [ PC::make(9) ] = 9; - m [ PC::make(10) ] = 10; - m [ PC::make(11) ] = 11; - m [ PC::make(12) ] = 12; - - R r = m.count(5); - assert(r == 1); - r = m.count(6); - assert(r == 1); - r = m.count(7); - assert(r == 1); - r = m.count(8); - assert(r == 1); - r = m.count(9); - assert(r == 1); - r = m.count(10); - assert(r == 1); - r = m.count(11); - assert(r == 1); - r = m.count(12); - assert(r == 1); - r = m.count(4); - assert(r == 0); + R r = m.count(i); + assert(r == 1); } +} + +int main(int, char**) +{ + test >(); +#if TEST_STD_VER >= 11 + typedef std::pair V; + test, min_allocator > >(); + test > >(); #endif +#if TEST_STD_VER > 11 + typedef std::map > TM; + test(); + test(); + + { + typedef PrivateConstructor PC; + typedef std::map > M; + typedef M::size_type R; + + M m; + m [ PC::make(5) ] = 5; + m [ PC::make(6) ] = 6; + m [ PC::make(7) ] = 7; + m [ PC::make(8) ] = 8; + m [ PC::make(9) ] = 9; + m [ PC::make(10) ] = 10; + m [ PC::make(11) ] = 11; + m [ PC::make(12) ] = 12; + + for (int i = 0; i < 5; ++i) + { + R r = m.count(i); + assert(r == 0); + } + for (int i = 5; i < 13; ++i) + { + R r = m.count(i); + assert(r == 1); + } + } +#endif return 0; }