Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60881 - in sandbox/statistics/detail/assign: boost/assign/auto_size/array boost/assign/auto_size/range boost/assign/auto_size/traits libs/assign/example libs/assign/src
From: erwann.rogard_at_[hidden]
Date: 2010-03-27 17:39:10


Author: e_r
Date: 2010-03-27 17:39:09 EDT (Sat, 27 Mar 2010)
New Revision: 60881
URL: http://svn.boost.org/trac/boost/changeset/60881

Log:
m
Text files modified:
   sandbox/statistics/detail/assign/boost/assign/auto_size/array/interface.hpp | 2
   sandbox/statistics/detail/assign/boost/assign/auto_size/range/chain.hpp | 2
   sandbox/statistics/detail/assign/boost/assign/auto_size/range/converter.hpp | 155 ++++++++++++++++++++++++++++++++++++++-
   sandbox/statistics/detail/assign/boost/assign/auto_size/traits/conversion_traits.hpp | 4
   sandbox/statistics/detail/assign/libs/assign/example/range.cpp | 2
   sandbox/statistics/detail/assign/libs/assign/src/main.cpp | 18 ++--
   6 files changed, 162 insertions(+), 21 deletions(-)

Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/array/interface.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/array/interface.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/array/interface.hpp 2010-03-27 17:39:09 EDT (Sat, 27 Mar 2010)
@@ -127,7 +127,7 @@
 
         public:
 
- BOOST_ASSIGN_AS_CONVERTER
+ BOOST_ASSIGN_AS_CONVERTER(this_)
 
 /*
         template< class Container >

Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/range/chain.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/range/chain.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/range/chain.hpp 2010-03-27 17:39:09 EDT (Sat, 27 Mar 2010)
@@ -158,7 +158,7 @@
 
         // This macro solves compiler complaints that otherwise occurr if
         // assign_detail::converter<> is a base
- BOOST_ASSIGN_AS_CONVERTER
+ BOOST_ASSIGN_AS_CONVERTER(this_)
         
     };
 

Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/range/converter.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/range/converter.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/range/converter.hpp 2010-03-27 17:39:09 EDT (Sat, 27 Mar 2010)
@@ -12,15 +12,156 @@
 #include <boost/range.hpp>
 
 // This brings the code within assign_detail::converter<> into a macro to be
-// expanded in what would otherwise be a derived class. This is done to solve
+// expanded in what would otherwise be a derived class. This is to solve
 // some compiler complaints in the presence of multiple inheritance.
 //
-// Warning: some compiler workarounds needed to be removed
-//
-// Requirements :
-// Expression Description
-// this_ type of the class within which this macro is expanded
+// Warning: some previous compiler workarounds were removed (for now).
 
+
+
+#define BOOST_ASSIGN_AS_CONVERTER(R) \
+ template< class Container > \
+ operator Container() const \
+ { \
+ return this->convert_to_container<Container>(); \
+ } \
+ template< class Container> \
+ Container convert_to_container() const{ \
+ return range_convert::convert_to_container<Container>(*this); } \
+ \
+ template< class Container> \
+ Container to_container( Container& c) const{ \
+ return range_convert::to_container(c,*this); } \
+ \
+ range_convert::impl::adapter_converter<R> \
+ to_adapter() const{ return range_convert::to_adapter(*this); } \
+ \
+ template<class Adapter> \
+ Adapter to_adapter( Adapter& a)const{ \
+ return range_convert::to_adapter(a,*this); } \
+ \
+ template<class Array> Array to_array( Array& a) const{ \
+ return to_array(a,*this); } \
+/**/
+
+namespace boost{
+namespace assign{
+namespace detail{
+namespace range_convert{
+namespace impl{
+
+ template< class Container, class R>
+ Container convert( const Container*,
+ assign_detail::default_type_tag, const R& r)
+ {
+ return Container( boost::begin(r), boost::end(r) );
+ }
+
+ template< class Array ,class R>
+ Array convert( const Array*, assign_detail::array_type_tag, const R& r )
+ {
+ typedef BOOST_DEDUCED_TYPENAME Array::value_type value_type;
+ typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<const R>::type it_;
+
+ Array ar;
+ const std::size_t sz = ar.size();
+ if( sz < boost::size( r ) )
+ throw assign::assignment_exception(
+ "array initialized with too many elements" );
+ std::size_t n = 0;
+ it_ i = boost::begin( r ) ;
+ it_ e = boost::end( r ) ;
+ for( ; i != e; ++i, ++n )
+ ar[n] = *i;
+ for( ; n < sz; ++n )
+ ar[n] = value_type();
+ return ar;
+ }
+
+ template< class Adapter ,class R>
+ Adapter convert_to_adapter(const R& r , const Adapter* = 0)
+ {
+ typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<const R>::type it_;
+ Adapter a;
+ it_ i = boost::begin( r );
+ it_ e = boost::end( r );
+ for( ; i != e; ++i )
+ a.push( *i );
+ return a;
+ }
+
+ template<class R>
+ struct adapter_converter
+ {
+ typedef typename boost::sub_range<const R>::type sub_;
+ adapter_converter( const R& r ) : sub( r )
+ {}
+
+ adapter_converter( const adapter_converter& a )
+ : sub( a.sub )
+ { }
+
+ template< class Adapter >
+ operator Adapter() const
+ {
+ return convert_to_adapter<Adapter>(sub);
+ }
+
+ private:
+ sub_ sub;
+ };
+}// impl
+
+ template< class Container,class R >
+ Container convert_to_container(const R& r)
+ {
+ static Container* c = 0;
+ BOOST_STATIC_CONSTANT(
+ bool,
+ is_array_flag = sizeof(
+ assign_detail::assign_is_array( c )
+ ) == sizeof( type_traits::yes_type )
+ );
+
+ typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c< is_array_flag,
+ assign_detail::array_type_tag,
+ assign_detail::default_type_tag >::type tag_type;
+
+ return range_convert::impl::convert<Container>( c, tag_type(), r );
+ }
+
+ template< class Container,class R >
+ Container to_container( Container& c,const R& r )
+ {
+ return range_convert::impl::convert( &c,
+ assign_detail::default_type_tag(),r );
+ }
+
+ template<class R>
+ impl::adapter_converter<R> to_adapter(const R& r)
+ {
+ return range_convert::impl::adapter_converter<R>( r );
+ }
+
+ template< class Adapter,class R >
+ Adapter to_adapter( Adapter& a ,const R& r)
+ {
+ return range_convert::impl::convert_to_adapter(r, &a);
+ }
+
+ template< class Array ,class R>
+ Array to_array( Array& a ,const R& r)
+ {
+ return range_convert::impl::convert(
+ &a, assign_detail::array_type_tag(),r );
+ }
+
+}// range_convert
+}// detail
+}// assign
+}// boost
+
+/*
 #define BOOST_ASSIGN_AS_CONVERTER \
                                                                                \
     public: \
@@ -43,7 +184,7 @@
                                                       assign_detail::array_type_tag, \
                                              assign_detail::default_type_tag >::type tag_type;\
                                                                                \
- return convert<Container>( c, tag_type() ); \
+ return this->convert<Container>( c, tag_type() ); \
         } \
                                                                                \
     protected: \

Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/traits/conversion_traits.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/traits/conversion_traits.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/traits/conversion_traits.hpp 2010-03-27 17:39:09 EDT (Sat, 27 Mar 2010)
@@ -42,7 +42,9 @@
     namespace meta{
         template<typename T> struct identity : boost::mpl::identity<T>{};
     
- template<typename Tag> struct convert_to{};
+ template<typename Tag> struct convert_to{
+ template<typename T> struct apply{};
+ };
 
         template<>
         struct convert_to<conversion_traits::tag::itself>{

Modified: sandbox/statistics/detail/assign/libs/assign/example/range.cpp
==============================================================================
--- sandbox/statistics/detail/assign/libs/assign/example/range.cpp (original)
+++ sandbox/statistics/detail/assign/libs/assign/example/range.cpp 2010-03-27 17:39:09 EDT (Sat, 27 Mar 2010)
@@ -36,6 +36,7 @@
     typedef boost::array<detail::assign_reference_copy<val_>,1> ref_array_;
 
 {
+/*
 
     BOOST_AUTO(tmp1,ref_list_of(a)(b));
     BOOST_AUTO(tmp2,ref_list_of(c)(d));
@@ -55,7 +56,6 @@
         chain_l(tmp1)(ar5)(tmp3),
         std::ostream_iterator<val_>(os," ")
     );
-/*
     os << ") becomes (";
     boost::copy(
         chain_l(ar1)(ar2)(ar3),

Modified: sandbox/statistics/detail/assign/libs/assign/src/main.cpp
==============================================================================
--- sandbox/statistics/detail/assign/libs/assign/src/main.cpp (original)
+++ sandbox/statistics/detail/assign/libs/assign/src/main.cpp 2010-03-27 17:39:09 EDT (Sat, 27 Mar 2010)
@@ -1,23 +1,21 @@
 #include <iostream>
 #define BOOST_ASSIGN_CHECK_EQUAL(a,b) BOOST_ASSERT(a==b)
-//#include <boost/assign/auto_size/check/ref_list_of.hpp>
+#include <boost/assign/auto_size/check/ref_list_of.hpp>
 //#include <boost/assign/auto_size/check/ref_csv.hpp>
 #undef BOOST_ASSIGN_CHECK_EQUAL
 #include <libs/assign/example/range.h>
 
 int main (int argc, char * const argv[]) {
 
- //using namespace boost::assign::detail::auto_size;
+ using namespace boost::assign::detail::auto_size;
 
- //void (*fp)();
+ void (*fp)();
     
- //fp = check_ref_list_of_example1<int>;
-
- //(*fp)();
-
- //std::cout << "check_ref_list_of : ok" << std::endl;
- //check_ref_csv_int();
- //std::cout << "check_csv : ok" << std::endl;
+ {
+ fp = check_ref_list_of_adapter_stack<int>;
+ (*fp)();
+ }
+ std::cout << "check_ref_list_of : ok" << std::endl;
 
     example_range(std::cout);
 


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