diff --git a/include/boost/unordered/unordered_map_fwd.hpp b/include/boost/unordered/unordered_map_fwd.hpp new file mode 100644 index 00000000..ceb77fc0 --- /dev/null +++ b/include/boost/unordered/unordered_map_fwd.hpp @@ -0,0 +1,53 @@ + +// Copyright (C) 2008 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_UNORDERED_MAP_FWD_HPP_INCLUDED +#define BOOST_UNORDERED_MAP_FWD_HPP_INCLUDED + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once +#endif + +#include +#include +#include +#include + +namespace boost +{ + template , + class Pred = std::equal_to, + class Alloc = std::allocator > > + class unordered_map; + template + bool operator==(unordered_map const&, + unordered_map const&); + template + bool operator!=(unordered_map const&, + unordered_map const&); + template + void swap(unordered_map&, + unordered_map&); + + template , + class Pred = std::equal_to, + class Alloc = std::allocator > > + class unordered_multimap; + template + bool operator==(unordered_multimap const&, + unordered_multimap const&); + template + bool operator!=(unordered_multimap const&, + unordered_multimap const&); + template + void swap(unordered_multimap&, + unordered_multimap&); +} + +#endif diff --git a/include/boost/unordered/unordered_set_fwd.hpp b/include/boost/unordered/unordered_set_fwd.hpp new file mode 100644 index 00000000..48a2caac --- /dev/null +++ b/include/boost/unordered/unordered_set_fwd.hpp @@ -0,0 +1,51 @@ + +// Copyright (C) 2008 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_UNORDERED_SET_FWD_HPP_INCLUDED +#define BOOST_UNORDERED_SET_FWD_HPP_INCLUDED + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once +#endif + +#include +#include +#include +#include + +namespace boost +{ + template , + class Pred = std::equal_to, + class Alloc = std::allocator > + class unordered_set; + template + bool operator==(unordered_set const&, + unordered_set const&); + template + bool operator!=(unordered_set const&, + unordered_set const&); + template + void swap(unordered_set &m1, + unordered_set &m2); + + template , + class Pred = std::equal_to, + class Alloc = std::allocator > + class unordered_multiset; + template + bool operator==(unordered_multiset const&, + unordered_multiset const&); + template + bool operator!=(unordered_multiset const&, + unordered_multiset const&); + template + void swap(unordered_multiset &m1, + unordered_multiset &m2); +} + +#endif diff --git a/include/boost/unordered_map.hpp b/include/boost/unordered_map.hpp index d675f07a..f4593517 100644 --- a/include/boost/unordered_map.hpp +++ b/include/boost/unordered_map.hpp @@ -13,11 +13,7 @@ # pragma once #endif -#include - -#include -#include - +#include #include #include @@ -27,38 +23,6 @@ namespace boost { - template , - class Pred = std::equal_to, - class Alloc = std::allocator > > - class unordered_map; - template - bool operator==(unordered_map const&, - unordered_map const&); - template - bool operator!=(unordered_map const&, - unordered_map const&); - template - void swap(unordered_map&, - unordered_map&); - - template , - class Pred = std::equal_to, - class Alloc = std::allocator > > - class unordered_multimap; - template - bool operator==(unordered_multimap const&, - unordered_multimap const&); - template - bool operator!=(unordered_multimap const&, - unordered_multimap const&); - template - void swap(unordered_multimap&, - unordered_multimap&); - template class unordered_map { diff --git a/include/boost/unordered_set.hpp b/include/boost/unordered_set.hpp index 4b850685..9e4f12b4 100644 --- a/include/boost/unordered_set.hpp +++ b/include/boost/unordered_set.hpp @@ -13,11 +13,7 @@ # pragma once #endif -#include - -#include -#include - +#include #include #include @@ -27,36 +23,6 @@ namespace boost { - template , - class Pred = std::equal_to, - class Alloc = std::allocator > - class unordered_set; - template - bool operator==(unordered_set const&, - unordered_set const&); - template - bool operator!=(unordered_set const&, - unordered_set const&); - template - void swap(unordered_set &m1, - unordered_set &m2); - - template , - class Pred = std::equal_to, - class Alloc = std::allocator > - class unordered_multiset; - template - bool operator==(unordered_multiset const&, - unordered_multiset const&); - template - bool operator!=(unordered_multiset const&, - unordered_multiset const&); - template - void swap(unordered_multiset &m1, - unordered_multiset &m2); - template class unordered_set { diff --git a/test/unordered/Jamfile.v2 b/test/unordered/Jamfile.v2 index d913e8e8..9ecec284 100644 --- a/test/unordered/Jamfile.v2 +++ b/test/unordered/Jamfile.v2 @@ -14,6 +14,8 @@ project unordered-test/unordered test-suite unordered : + [ run fwd_set_test.cpp ] + [ run fwd_map_test.cpp ] [ run compile_set.cpp ] [ run compile_map.cpp ] [ run link_test_1.cpp link_test_2.cpp ] diff --git a/test/unordered/fwd_map_test.cpp b/test/unordered/fwd_map_test.cpp new file mode 100644 index 00000000..a0d118e5 --- /dev/null +++ b/test/unordered/fwd_map_test.cpp @@ -0,0 +1,62 @@ + +// Copyright 2008 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include + +typedef boost::unordered_map int_map; + +void call_swap(int_map& x, int_map& y) { + swap(x,y); +} + +bool call_equals(int_map& x, int_map& y) { + return x == y; +} + +bool call_not_equals(int_map& x, int_map& y) { + return x != y; +} + +typedef boost::unordered_multimap int_multimap; + +void call_swap(int_multimap& x, int_multimap& y) { + swap(x,y); +} + +bool call_equals(int_multimap& x, int_multimap& y) { + return x == y; +} + +bool call_not_equals(int_multimap& x, int_multimap& y) { + return x != y; +} + +#include +#include "../helpers/test.hpp" + +UNORDERED_AUTO_TEST(use_map_fwd_declared_function) { + int_map x, y; + x[1] = 2; + y[2] = 1; + call_swap(x, y); + + BOOST_CHECK(y.find(1) != y.end() && y.find(1)->second == 2); + BOOST_CHECK(y.find(2) == y.end()); + + BOOST_CHECK(x.find(1) == x.end()); + BOOST_CHECK(x.find(2) != x.end() && x.find(2)->second == 1); + + BOOST_CHECK(!call_equals(x, y)); + BOOST_CHECK(call_not_equals(x, y)); +} + +UNORDERED_AUTO_TEST(use_multimap_fwd_declared_function) { + int_multimap x, y; + call_swap(x, y); + BOOST_CHECK(call_equals(x, y)); + BOOST_CHECK(!call_not_equals(x, y)); +} + +RUN_TESTS() diff --git a/test/unordered/fwd_set_test.cpp b/test/unordered/fwd_set_test.cpp new file mode 100644 index 00000000..3b39f8b3 --- /dev/null +++ b/test/unordered/fwd_set_test.cpp @@ -0,0 +1,84 @@ + +// Copyright 2008 Daniel James. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include + +struct true_type { char x[100]; }; +struct false_type { char x; }; + +false_type is_unordered_set_impl(void*); + +template +true_type is_unordered_set_impl( + boost::unordered_set*); + +typedef boost::unordered_set int_set; + +void call_swap(int_set& x, int_set& y) { + swap(x,y); +} + +bool call_equals(int_set& x, int_set& y) { + return x == y; +} + +bool call_not_equals(int_set& x, int_set& y) { + return x != y; +} + +typedef boost::unordered_multiset int_multiset; + +void call_swap(int_multiset& x, int_multiset& y) { + swap(x,y); +} + +bool call_equals(int_multiset& x, int_multiset& y) { + return x == y; +} + +bool call_not_equals(int_multiset& x, int_multiset& y) { + return x != y; +} + +#include "../helpers/test.hpp" + +UNORDERED_AUTO_TEST(use_fwd_declared_trait_without_definition) { + BOOST_CHECK(sizeof(is_unordered_set_impl((int_set*) 0)) == sizeof(true_type)); +} + +#include + +UNORDERED_AUTO_TEST(use_fwd_declared_trait) { + boost::unordered_set x; + BOOST_CHECK(sizeof(is_unordered_set_impl(&x)) == sizeof(true_type)); + + int dummy; + BOOST_CHECK(sizeof(is_unordered_set_impl(&dummy)) == sizeof(false_type)); +} + +UNORDERED_AUTO_TEST(use_set_fwd_declared_function) { + int_set x, y; + x.insert(1); + y.insert(2); + call_swap(x, y); + + BOOST_CHECK(y.find(1) != y.end()); + BOOST_CHECK(y.find(2) == y.end()); + + BOOST_CHECK(x.find(1) == x.end()); + BOOST_CHECK(x.find(2) != x.end()); + + BOOST_CHECK(!call_equals(x, y)); + BOOST_CHECK(call_not_equals(x, y)); +} + +UNORDERED_AUTO_TEST(use_multiset_fwd_declared_function) { + int_multiset x, y; + call_swap(x, y); + BOOST_CHECK(call_equals(x, y)); + BOOST_CHECK(!call_not_equals(x, y)); +} + +RUN_TESTS()