Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r48802 - in trunk: boost boost/unordered libs/unordered/test/unordered
From: daniel_james_at_[hidden]
Date: 2008-09-16 17:45:54


Author: danieljames
Date: 2008-09-16 17:45:53 EDT (Tue, 16 Sep 2008)
New Revision: 48802
URL: http://svn.boost.org/trac/boost/changeset/48802

Log:
Forward headers for the unordered containers.
Added:
   trunk/boost/unordered/unordered_map_fwd.hpp (contents, props changed)
   trunk/boost/unordered/unordered_set_fwd.hpp (contents, props changed)
   trunk/libs/unordered/test/unordered/fwd_map_test.cpp (contents, props changed)
   trunk/libs/unordered/test/unordered/fwd_set_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/unordered_map.hpp | 38 +-------------------------------------
   trunk/boost/unordered_set.hpp | 36 +-----------------------------------
   trunk/libs/unordered/test/unordered/Jamfile.v2 | 2 ++
   3 files changed, 4 insertions(+), 72 deletions(-)

Added: trunk/boost/unordered/unordered_map_fwd.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/unordered/unordered_map_fwd.hpp 2008-09-16 17:45:53 EDT (Tue, 16 Sep 2008)
@@ -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 <boost/config.hpp>
+#include <memory>
+#include <functional>
+#include <boost/functional/hash_fwd.hpp>
+
+namespace boost
+{
+ template <class Key,
+ class T,
+ class Hash = hash<Key>,
+ class Pred = std::equal_to<Key>,
+ class Alloc = std::allocator<std::pair<const Key, T> > >
+ class unordered_map;
+ template <class K, class T, class H, class P, class A>
+ bool operator==(unordered_map<K, T, H, P, A> const&,
+ unordered_map<K, T, H, P, A> const&);
+ template <class K, class T, class H, class P, class A>
+ bool operator!=(unordered_map<K, T, H, P, A> const&,
+ unordered_map<K, T, H, P, A> const&);
+ template <class K, class T, class H, class P, class A>
+ void swap(unordered_map<K, T, H, P, A>&,
+ unordered_map<K, T, H, P, A>&);
+
+ template <class Key,
+ class T,
+ class Hash = hash<Key>,
+ class Pred = std::equal_to<Key>,
+ class Alloc = std::allocator<std::pair<const Key, T> > >
+ class unordered_multimap;
+ template <class K, class T, class H, class P, class A>
+ bool operator==(unordered_multimap<K, T, H, P, A> const&,
+ unordered_multimap<K, T, H, P, A> const&);
+ template <class K, class T, class H, class P, class A>
+ bool operator!=(unordered_multimap<K, T, H, P, A> const&,
+ unordered_multimap<K, T, H, P, A> const&);
+ template <class K, class T, class H, class P, class A>
+ void swap(unordered_multimap<K, T, H, P, A>&,
+ unordered_multimap<K, T, H, P, A>&);
+}
+
+#endif

Added: trunk/boost/unordered/unordered_set_fwd.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/unordered/unordered_set_fwd.hpp 2008-09-16 17:45:53 EDT (Tue, 16 Sep 2008)
@@ -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 <boost/config.hpp>
+#include <memory>
+#include <functional>
+#include <boost/functional/hash_fwd.hpp>
+
+namespace boost
+{
+ template <class Value,
+ class Hash = hash<Value>,
+ class Pred = std::equal_to<Value>,
+ class Alloc = std::allocator<Value> >
+ class unordered_set;
+ template <class T, class H, class P, class A>
+ bool operator==(unordered_set<T, H, P, A> const&,
+ unordered_set<T, H, P, A> const&);
+ template <class T, class H, class P, class A>
+ bool operator!=(unordered_set<T, H, P, A> const&,
+ unordered_set<T, H, P, A> const&);
+ template <class T, class H, class P, class A>
+ void swap(unordered_set<T, H, P, A> &m1,
+ unordered_set<T, H, P, A> &m2);
+
+ template <class Value,
+ class Hash = hash<Value>,
+ class Pred = std::equal_to<Value>,
+ class Alloc = std::allocator<Value> >
+ class unordered_multiset;
+ template <class T, class H, class P, class A>
+ bool operator==(unordered_multiset<T, H, P, A> const&,
+ unordered_multiset<T, H, P, A> const&);
+ template <class T, class H, class P, class A>
+ bool operator!=(unordered_multiset<T, H, P, A> const&,
+ unordered_multiset<T, H, P, A> const&);
+ template <class T, class H, class P, class A>
+ void swap(unordered_multiset<T, H, P, A> &m1,
+ unordered_multiset<T, H, P, A> &m2);
+}
+
+#endif

Modified: trunk/boost/unordered_map.hpp
==============================================================================
--- trunk/boost/unordered_map.hpp (original)
+++ trunk/boost/unordered_map.hpp 2008-09-16 17:45:53 EDT (Tue, 16 Sep 2008)
@@ -13,11 +13,7 @@
 # pragma once
 #endif
 
-#include <boost/config.hpp>
-
-#include <functional>
-#include <memory>
-
+#include <boost/unordered/unordered_map_fwd.hpp>
 #include <boost/functional/hash.hpp>
 #include <boost/unordered/detail/hash_table.hpp>
 
@@ -27,38 +23,6 @@
 
 namespace boost
 {
- template <class Key,
- class T,
- class Hash = hash<Key>,
- class Pred = std::equal_to<Key>,
- class Alloc = std::allocator<std::pair<const Key, T> > >
- class unordered_map;
- template <class K, class T, class H, class P, class A>
- bool operator==(unordered_map<K, T, H, P, A> const&,
- unordered_map<K, T, H, P, A> const&);
- template <class K, class T, class H, class P, class A>
- bool operator!=(unordered_map<K, T, H, P, A> const&,
- unordered_map<K, T, H, P, A> const&);
- template <class K, class T, class H, class P, class A>
- void swap(unordered_map<K, T, H, P, A>&,
- unordered_map<K, T, H, P, A>&);
-
- template <class Key,
- class T,
- class Hash = hash<Key>,
- class Pred = std::equal_to<Key>,
- class Alloc = std::allocator<std::pair<const Key, T> > >
- class unordered_multimap;
- template <class K, class T, class H, class P, class A>
- bool operator==(unordered_multimap<K, T, H, P, A> const&,
- unordered_multimap<K, T, H, P, A> const&);
- template <class K, class T, class H, class P, class A>
- bool operator!=(unordered_multimap<K, T, H, P, A> const&,
- unordered_multimap<K, T, H, P, A> const&);
- template <class K, class T, class H, class P, class A>
- void swap(unordered_multimap<K, T, H, P, A>&,
- unordered_multimap<K, T, H, P, A>&);
-
     template <class Key, class T, class Hash, class Pred, class Alloc>
     class unordered_map
     {

Modified: trunk/boost/unordered_set.hpp
==============================================================================
--- trunk/boost/unordered_set.hpp (original)
+++ trunk/boost/unordered_set.hpp 2008-09-16 17:45:53 EDT (Tue, 16 Sep 2008)
@@ -13,11 +13,7 @@
 # pragma once
 #endif
 
-#include <boost/config.hpp>
-
-#include <functional>
-#include <memory>
-
+#include <boost/unordered/unordered_set_fwd.hpp>
 #include <boost/functional/hash.hpp>
 #include <boost/unordered/detail/hash_table.hpp>
 
@@ -27,36 +23,6 @@
 
 namespace boost
 {
- template <class Value,
- class Hash = hash<Value>,
- class Pred = std::equal_to<Value>,
- class Alloc = std::allocator<Value> >
- class unordered_set;
- template <class T, class H, class P, class A>
- bool operator==(unordered_set<T, H, P, A> const&,
- unordered_set<T, H, P, A> const&);
- template <class T, class H, class P, class A>
- bool operator!=(unordered_set<T, H, P, A> const&,
- unordered_set<T, H, P, A> const&);
- template <class T, class H, class P, class A>
- void swap(unordered_set<T, H, P, A> &m1,
- unordered_set<T, H, P, A> &m2);
-
- template <class Value,
- class Hash = hash<Value>,
- class Pred = std::equal_to<Value>,
- class Alloc = std::allocator<Value> >
- class unordered_multiset;
- template <class T, class H, class P, class A>
- bool operator==(unordered_multiset<T, H, P, A> const&,
- unordered_multiset<T, H, P, A> const&);
- template <class T, class H, class P, class A>
- bool operator!=(unordered_multiset<T, H, P, A> const&,
- unordered_multiset<T, H, P, A> const&);
- template <class T, class H, class P, class A>
- void swap(unordered_multiset<T, H, P, A> &m1,
- unordered_multiset<T, H, P, A> &m2);
-
     template <class Value, class Hash, class Pred, class Alloc>
     class unordered_set
     {

Modified: trunk/libs/unordered/test/unordered/Jamfile.v2
==============================================================================
--- trunk/libs/unordered/test/unordered/Jamfile.v2 (original)
+++ trunk/libs/unordered/test/unordered/Jamfile.v2 2008-09-16 17:45:53 EDT (Tue, 16 Sep 2008)
@@ -14,6 +14,8 @@
 
 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 ]

Added: trunk/libs/unordered/test/unordered/fwd_map_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/unordered/test/unordered/fwd_map_test.cpp 2008-09-16 17:45:53 EDT (Tue, 16 Sep 2008)
@@ -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 <boost/unordered/unordered_map_fwd.hpp>
+
+typedef boost::unordered_map<int, int> 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, int> 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 <boost/unordered_map.hpp>
+#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()

Added: trunk/libs/unordered/test/unordered/fwd_set_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/unordered/test/unordered/fwd_set_test.cpp 2008-09-16 17:45:53 EDT (Tue, 16 Sep 2008)
@@ -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 <boost/unordered/unordered_set_fwd.hpp>
+
+struct true_type { char x[100]; };
+struct false_type { char x; };
+
+false_type is_unordered_set_impl(void*);
+
+template <class Value, class Hash, class Pred, class Alloc>
+true_type is_unordered_set_impl(
+ boost::unordered_set<Value, Hash, Pred, Alloc>*);
+
+typedef boost::unordered_set<int> 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> 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 <boost/unordered_set.hpp>
+
+UNORDERED_AUTO_TEST(use_fwd_declared_trait) {
+ boost::unordered_set<int> 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()


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk