|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r80989 - trunk/boost/format
From: steven_at_[hidden]
Date: 2012-10-14 21:28:53
Author: steven_watanabe
Date: 2012-10-14 21:28:53 EDT (Sun, 14 Oct 2012)
New Revision: 80989
URL: http://svn.boost.org/trac/boost/changeset/80989
Log:
Reduce code bloat from boost::format. Fixes #4700.
Text files modified:
trunk/boost/format/feed_args.hpp | 41 +++++++++++++++++++++++++++++++++++++++
trunk/boost/format/format_class.hpp | 2
trunk/boost/format/internals_fwd.hpp | 4 +++
3 files changed, 45 insertions(+), 2 deletions(-)
Modified: trunk/boost/format/feed_args.hpp
==============================================================================
--- trunk/boost/format/feed_args.hpp (original)
+++ trunk/boost/format/feed_args.hpp 2012-10-14 21:28:53 EDT (Sun, 14 Oct 2012)
@@ -117,6 +117,39 @@
#endif
#endif // -msvc workaround
+ template< class Ch, class Tr, class T>
+ void call_put_head(BOOST_IO_STD basic_ostream<Ch, Tr> & os, const void* x) {
+ put_head(os, *(typename ::boost::remove_reference<T>::type*)x);
+ }
+
+ template< class Ch, class Tr, class T>
+ void call_put_last(BOOST_IO_STD basic_ostream<Ch, Tr> & os, const void* x) {
+ put_last(os, *(T*)x);
+ }
+
+ template< class Ch, class Tr>
+ struct put_holder {
+ template<class T>
+ put_holder(T& t)
+ : arg(&t),
+ put_head(&call_put_head<Ch, Tr, T>),
+ put_last(&call_put_last<Ch, Tr, T>)
+ {}
+ const void* arg;
+ void (*put_head)(BOOST_IO_STD basic_ostream<Ch, Tr> & os, const void* x);
+ void (*put_last)(BOOST_IO_STD basic_ostream<Ch, Tr> & os, const void* x);
+ };
+
+ template< class Ch, class Tr> inline
+ void put_head( BOOST_IO_STD basic_ostream<Ch, Tr> & os, const put_holder<Ch, Tr>& t) {
+ t.put_head(os, t.arg);
+ }
+
+ template< class Ch, class Tr> inline
+ void put_last( BOOST_IO_STD basic_ostream<Ch, Tr> & os, const put_holder<Ch, Tr>& t) {
+ t.put_last(os, t.arg);
+ }
+
template< class Ch, class Tr, class Alloc, class T>
void put( T x,
@@ -258,7 +291,7 @@
template<class Ch, class Tr, class Alloc, class T>
basic_format<Ch, Tr, Alloc>&
- feed (basic_format<Ch,Tr, Alloc>& self, T x) {
+ feed_impl (basic_format<Ch,Tr, Alloc>& self, T x) {
if(self.dumped_) self.clear();
distribute<Ch, Tr, Alloc, T> (self, x);
++self.cur_arg_;
@@ -268,6 +301,12 @@
}
return self;
}
+
+ template<class Ch, class Tr, class Alloc, class T> inline
+ basic_format<Ch, Tr, Alloc>&
+ feed (basic_format<Ch,Tr, Alloc>& self, T x) {
+ return feed_impl<Ch, Tr, Alloc, const put_holder<Ch, Tr>&>(self, put_holder<Ch, Tr>(x));
+ }
} // namespace detail
} // namespace io
Modified: trunk/boost/format/format_class.hpp
==============================================================================
--- trunk/boost/format/format_class.hpp (original)
+++ trunk/boost/format/format_class.hpp 2012-10-14 21:28:53 EDT (Sun, 14 Oct 2012)
@@ -126,7 +126,7 @@
template<class Ch2, class Tr2, class Alloc2, class T>
friend basic_format<Ch2, Tr2, Alloc2>&
- io::detail::feed (basic_format<Ch2, Tr2, Alloc2>&, T);
+ io::detail::feed_impl (basic_format<Ch2, Tr2, Alloc2>&, T);
template<class Ch2, class Tr2, class Alloc2, class T> friend
void io::detail::distribute (basic_format<Ch2, Tr2, Alloc2>&, T);
Modified: trunk/boost/format/internals_fwd.hpp
==============================================================================
--- trunk/boost/format/internals_fwd.hpp (original)
+++ trunk/boost/format/internals_fwd.hpp 2012-10-14 21:28:53 EDT (Sun, 14 Oct 2012)
@@ -50,6 +50,10 @@
template<class Ch, class Tr, class Alloc, class T>
basic_format<Ch, Tr, Alloc>&
feed (basic_format<Ch,Tr, Alloc>& self, T x);
+
+ template<class Ch, class Tr, class Alloc, class T>
+ basic_format<Ch, Tr, Alloc>&
+ feed_impl (basic_format<Ch,Tr, Alloc>& self, T x);
} // namespace detail
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