|
Boost-Commit : |
From: jefffaust_at_[hidden]
Date: 2007-05-27 09:50:50
Author: jefffaust
Date: 2007-05-27 09:50:49 EDT (Sun, 27 May 2007)
New Revision: 4312
URL: http://svn.boost.org/trac/boost/changeset/4312
Log:
Move stream operators to namespace of what they are streaming.
Disable printing arrays on msvc 7.1
Text files modified:
sandbox/explore/boost/explore/stream_container.hpp | 66 +++++++++++++++++++++++----------------
1 files changed, 39 insertions(+), 27 deletions(-)
Modified: sandbox/explore/boost/explore/stream_container.hpp
==============================================================================
--- sandbox/explore/boost/explore/stream_container.hpp (original)
+++ sandbox/explore/boost/explore/stream_container.hpp 2007-05-27 09:50:49 EDT (Sun, 27 May 2007)
@@ -16,7 +16,7 @@
#include <boost/functional/detail/container_fwd.hpp>
#include <boost/array.hpp>
-namespace boost
+namespace explore
{
namespace detail
{
@@ -162,54 +162,51 @@
// redirect with "normal" streaming.
return stream_container(ostr, first, last, stream_normal_value());
}
+}
+namespace std
+{
// stream vector<T>
template<typename Elem, typename Tr, typename T>
std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const std::vector<T>& v)
{
- return stream_container(ostr, v.begin(), v.end());
+ return explore::stream_container(ostr, v.begin(), v.end());
}
// stream deque<T>
template<typename Elem, typename Tr, typename T, typename Allocator>
std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const std::deque<T, Allocator>& d)
{
- return stream_container(ostr, d.begin(), d.end());
+ return explore::stream_container(ostr, d.begin(), d.end());
}
// stream set<T>
template<typename Elem, typename Tr, typename T, typename Compare, typename Alloc>
std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const std::set<T, Compare, Alloc>& s)
{
- return stream_container(ostr, s.begin(), s.end());
+ return explore::stream_container(ostr, s.begin(), s.end());
}
// stream multiset<T>
template<typename Elem, typename Tr, typename T, typename Compare, typename Allocator>
std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const std::multiset<T, Compare, Allocator>& s)
{
- return stream_container(ostr, s.begin(), s.end());
+ return explore::stream_container(ostr, s.begin(), s.end());
}
// stream list<T>
template<typename Elem, typename Tr, typename T, typename Allocator>
std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const std::list<T, Allocator>& l)
{
- return stream_container(ostr, l.begin(), l.end());
- }
-
- // stream array<T>
- template<typename Elem, typename Tr, typename T, std::size_t N>
- std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const boost::array<T, N>& a)
- {
- return stream_container(ostr, a.begin(), a.end());
+ return explore::stream_container(ostr, l.begin(), l.end());
}
// stream pair<T1, T2>
template<typename Elem, typename Tr, typename T1, typename T2>
std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const std::pair<T1, T2>& p)
{
- container_stream_state<Elem, Tr>* state = explore::get_stream_state<container_stream_state<Elem, Tr> >(ostr);
+ using namespace explore;
+ container_stream_state<Elem, Tr>* state = get_stream_state<container_stream_state<Elem, Tr> >(ostr);
return ostr << state->start << p.first << state->separator << p.second << state->end;
}
@@ -217,6 +214,7 @@
template<typename Elem, typename Tr, typename K, typename T, typename Compare, typename Allocator>
std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const std::map<K, T, Compare, Allocator>& m)
{
+ using namespace explore;
return stream_container(ostr, m.begin(), m.end(), stream_map_value());
}
@@ -224,22 +222,26 @@
template<typename Elem, typename Tr, typename K, typename T, typename Compare, typename Allocator>
std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const std::multimap<K, T, Compare, Allocator>& m)
{
+ using namespace explore;
return stream_container(ostr, m.begin(), m.end(), stream_map_value());
}
+}
+
+namespace explore
+{
+# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
+ template<typename Elem, typename Tr, typename T, std::size_t size>
+ std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, T (&a)[size])
+ {
+ return stream_container(ostr, &a[0], &a[size]);
+ }
- // stream c-array - conflicts with char* streaming in VC7.1
- //template<typename Elem, typename Tr, typename T, std::size_t size>
- //std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, T (&a)[size])
- //{
- // return stream_container(ostr, &a[0], &a[size]);
- //}
-
- // Boost.Range -- there is already a streaming operator defined, although it does not do what we want.
- //template<typename Elem, typename Tr, typename Range>
- //std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, boost::iterator_range<Range>& r)
- //{
- // return stream_container(ostr, boost::begin(r), boost::end(r));
- //}
+ template<typename Elem, typename Tr, std::size_t size>
+ std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const Elem* s)
+ {
+ return stream_container(ostr, &s[0], &s[strlen(s)]);
+ }
+# endif
// function ptr for separator manipulator
template<typename Elem, typename Tr>
@@ -301,4 +303,14 @@
}
}
+namespace boost
+{
+ // stream boost::array<T>
+ template<typename Elem, typename Tr, typename T, std::size_t N>
+ std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const boost::array<T, N>& a)
+ {
+ return explore::stream_container(ostr, a.begin(), a.end());
+ }
+}
+
#endif
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