Boost logo

Boost-Commit :

From: dannyh_at_[hidden]
Date: 2007-07-03 19:32:23


Author: dannyh
Date: 2007-07-03 19:32:23 EDT (Tue, 03 Jul 2007)
New Revision: 7353
URL: http://svn.boost.org/trac/boost/changeset/7353

Log:
protected print from 'hostile' operator<< overloads for std containers.

Text files modified:
   sandbox/explore/boost/explore/explore.hpp | 46 ++++++++++++++++++++++++++++++++++++---
   1 files changed, 42 insertions(+), 4 deletions(-)

Modified: sandbox/explore/boost/explore/explore.hpp
==============================================================================
--- sandbox/explore/boost/explore/explore.hpp (original)
+++ sandbox/explore/boost/explore/explore.hpp 2007-07-03 19:32:23 EDT (Tue, 03 Jul 2007)
@@ -15,8 +15,8 @@
 #define __EXPLORE_HPP_INCLUDED__
 
 #include <iostream>
-#include <map>
 #include <iterator>
+#include <boost/functional/detail/container_fwd.hpp>
 #include <boost/mpl/bool.hpp>
 #include <boost/mpl/if.hpp>
 #include <boost/mpl/eval_if.hpp>
@@ -32,7 +32,6 @@
 #include <boost/range/const_iterator.hpp>
 #include <boost/range/functions.hpp>
 #include <boost/range/iterator_range.hpp>
-
 #include "iterator_range.hpp"
 
 
@@ -97,6 +96,44 @@
     template< typename T>
     struct print_as_container< boost::iterator_range<T> > : true_ {};
 
+ //
+ // oh, what the heck. Let's overload for explore::iterator_range
+ // as well, just in case somebody uses this one by accident for
+ // the print function.
+ //
+ template< typename T>
+ struct print_as_container< explore::iterator_range<T> > : true_ {};
+
+
+ //
+ // make sure we use streaming for std containers
+ //
+ template <class T, class Allocator>
+ struct print_as_container< std::deque< T, Allocator> > : true_ {};
+
+ template <class T, class Allocator>
+ struct print_as_container< std::list<T, Allocator> > : true_ {};
+
+ template <class T, class Allocator>
+ struct print_as_container< std::vector<T, Allocator> > : true_ {};
+
+ template <class Key, class T, class Compare, class Allocator>
+ struct print_as_container< std::map<Key,T, Compare, Allocator> > : true_ {};
+
+ template <class Key, class T, class Compare, class Allocator>
+ struct print_as_container< std::multimap<Key,T, Compare, Allocator> > : true_ {};
+
+ template <class Key, class Compare, class Allocator>
+ struct print_as_container< std::set<Key, Compare, Allocator> > : true_ {};
+
+ template <class Key, class Compare, class Allocator>
+ struct print_as_container< std::multiset<Key, Compare, Allocator> > : true_ {};
+
+ template <class T1, class T2>
+ struct print_as_container< std::pair<T1,T2> > : true_ {};
+
+
+
 
     //
     // is_map metafunction, probably needs to be extended for
@@ -127,6 +164,7 @@
         struct print_as_container : explore::print_as_container<T> {};
     };
 
+
     //
     // Meta functions that are used by the default implementation of format
     // These mainly deal with the fact that a format is a sequence of range
@@ -399,13 +437,13 @@
     const format_type &format,
     const container_policy_type &policy)
     {
- return print( explore::make_iterator_range(first, last), stream, format, policy );
+ return print( boost::make_iterator_range(first, last), stream, format, policy );
     }
 
     template<class InputIterator>
     std::ostream &print(InputIterator first, InputIterator last, std::ostream &stream = std::cout)
     {
- return print( explore::make_iterator_range(first, last), stream );
+ return print( boost::make_iterator_range(first, last), stream );
     }
 
 


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