Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60360 - in sandbox/statistics/detail/assign: boost/assign/auto_size boost/assign/auto_size/array boost/assign/auto_size/detail libs/assign/doc libs/assign/example libs/assign/src libs/assign/test
From: erwann.rogard_at_[hidden]
Date: 2010-03-08 13:00:46


Author: e_r
Date: 2010-03-08 13:00:45 EST (Mon, 08 Mar 2010)
New Revision: 60360
URL: http://svn.boost.org/trac/boost/changeset/60360

Log:
m
Text files modified:
   sandbox/statistics/detail/assign/boost/assign/auto_size/array/interface.hpp | 114 +++++-------
   sandbox/statistics/detail/assign/boost/assign/auto_size/detail/assign_reference_copy.hpp | 23 ++
   sandbox/statistics/detail/assign/boost/assign/auto_size/detail/expr.hpp | 10
   sandbox/statistics/detail/assign/boost/assign/auto_size/detail/has_copy_semantics.hpp | 6
   sandbox/statistics/detail/assign/boost/assign/auto_size/detail/has_static_size.hpp | 46 +---
   sandbox/statistics/detail/assign/boost/assign/auto_size/ref_list_of.hpp | 5
   sandbox/statistics/detail/assign/boost/assign/auto_size/ref_rebind_list_of.hpp | 6
   sandbox/statistics/detail/assign/libs/assign/doc/revision_history.txt | 4
   sandbox/statistics/detail/assign/libs/assign/example/ref_list_of.cpp | 353 +++++++++++++++++++++++++++++----------
   sandbox/statistics/detail/assign/libs/assign/src/main.cpp | 6
   sandbox/statistics/detail/assign/libs/assign/test/static_list_of_auto_size.cpp | 174 ++++++++++++++++--
   11 files changed, 518 insertions(+), 229 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-08 13:00:45 EST (Mon, 08 Mar 2010)
@@ -14,27 +14,17 @@
 #include <boost/range.hpp>
 #include <boost/assign/auto_size/detail/has_copy_semantics.hpp>
 #include <boost/assign/auto_size/array/ref.hpp>
+#include <boost/assign/list_of.hpp> // for assign_detail::converter
 
 namespace boost{
 namespace assign{
 namespace detail{
 namespace auto_size{
-
- // Used as a base class of D, adds the array interface and a conversion
- // operator to any data-structure constructible from a pair of iterators.
- //
- // Requirements: let d1 and d2 instances of D and const D, respectively
- // Valid expression Result
- // d1.ref_array_impl() array_interface::ref_array_&
- // d2.ref_array_impl() array_interface::const ref_array_&
- template<typename T,int N,template<typename> class R,typename D>
- struct array_interface{
+
+ template<typename T,int N,template<typename> class R>
+ struct array_interface_traits{
         typedef typename R<T>::type ref_;
         typedef typename ref_array<T,N,R>::type ref_array_;
-
-
- // ---- boost::array ---- //
-
         typedef ref_ value_type;
         typedef typename
                 boost::range_iterator<ref_array_>::type iterator;
@@ -44,40 +34,46 @@
                 boost::range_size<ref_array_>::type size_type;
         typedef typename boost::range_difference<
             ref_array_>::type difference_type;
-
- BOOST_STATIC_CONSTANT(int, static_size = N);
-
- iterator begin()
- {
- return boost::begin(this->ref_array());
- }
- iterator end()
- {
- return boost::end(this->ref_array());
- }
-
- const_iterator begin()const
- {
- return boost::begin(this->ref_array());
- }
- const_iterator end()const
- {
- return boost::end(this->ref_array());
- }
-
- size_type size() const
- {
- return ref_array_::size();
- }
- bool empty() const
- {
- return !(this->size());
- }
-
         typedef typename ref_array_::reference reference;
         typedef typename
                 ref_array_::const_reference const_reference;
 
+ };
+
+ // Used as a base class of D, adds the array and conversion interface
+ //
+ // Requirements: let d1 and d2 instances of D and const D, respectively
+ // Valid expression Result
+ // d1.ref_array_impl() array_interface::ref_array_&
+ // d2.ref_array_impl() array_interface::const ref_array_&
+ template<typename T,std::size_t N,template<typename> class R,typename D>
+ class array_interface : public assign_detail::converter<
+ array_interface<T,N,R,D>,
+ typename array_interface_traits<T,N,R>::const_iterator
+ >{
+ typedef array_interface_traits<T,N,R> traits;
+ typedef typename traits::ref_ ref_;
+ typedef typename traits::ref_array_ ref_array_;
+
+ public:
+ typedef ref_ value_type;
+ typedef typename traits::iterator iterator;
+ typedef typename traits::const_iterator const_iterator;
+ typedef typename traits::size_type size_type;
+ typedef typename traits::difference_type difference_type;
+ typedef typename traits::reference reference;
+ typedef typename traits::const_reference const_reference;
+
+ BOOST_STATIC_CONSTANT(size_type, static_size = N);
+
+ iterator begin() { return boost::begin(this->ref_array()); }
+ iterator end() { return boost::end(this->ref_array()); }
+
+ const_iterator begin()const { return boost::begin(this->ref_array()); }
+ const_iterator end()const { return boost::end(this->ref_array()); }
+ size_type size() const{ return this->ref_array().size(); }
+ bool empty() const{ return this->ref_array().empty(); }
+
         reference operator[](size_type i){ return (this->ref_array())[i]; }
         const_reference operator[](size_type i)const{
              return (this->array())[i]; }
@@ -87,32 +83,19 @@
         reference back(){ return (this->ref_array()).back(); }
         const_reference back() const{ return (this->ref_array()).back(); }
         
- void swap(ref_array_& other){ return (this->ref_array()).swap(other); }
+ void swap(array_interface& other){
+ (this->ref_array()).swap(other.ref_array());
+ }
         void assign(const T& val){
             typedef has_copy_semantics<ref_> pred_;
             return this->assign(val,pred_());
         }
 
- // ---- Conversion ---- //
-
- template<typename T1>
- operator boost::array<T1,N>()const{
- boost::array<T1,N> ar;
- std::copy(
- boost::begin(this->ref_array()),
- boost::end(this->ref_array()),
- boost::begin(ar)
- );
- return ar;
- }
-
- template<typename C>
- operator C ()const
+ template< class Container >
+ operator Container() const
         {
- return C(
- boost::begin(this->ref_array()),
- boost::end(this->ref_array())
- );
+ return
+ this-> BOOST_NESTED_TEMPLATE convert_to_container<Container>();
         }
 
         private:
@@ -126,7 +109,7 @@
         }
 
         void assign(const T& val,false_ /*copy semantics*/){
- return this->ref_array().assign(val);
+ this->ref_array().assign(val);
         }
         
         ref_array_& ref_array(){
@@ -139,6 +122,7 @@
 
     };
 
+
 }// auto_size
 }// detail
 }// assign

Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/detail/assign_reference_copy.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/detail/assign_reference_copy.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/detail/assign_reference_copy.hpp 2010-03-08 13:00:45 EST (Mon, 08 Mar 2010)
@@ -57,6 +57,29 @@
         T* ref_;
 
     };
+
+ // Added by ER March 7, 2010
+ template< class T >
+ inline bool operator<( const assign_reference_copy<T>& l,
+ const assign_reference_copy<T>& r )
+ {
+ return l.get_ref() < r.get_ref();
+ }
+
+ template< class T >
+ inline bool operator>( const assign_reference_copy<T>& l,
+ const assign_reference_copy<T>& r )
+ {
+ return l.get_ref() > r.get_ref();
+ }
+
+ template< class T >
+ inline void swap( assign_reference_copy<T>& l,
+ assign_reference_copy<T>& r )
+ {
+ l.swap( r );
+ }
+
     
 }// detail
 }// assign

Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/detail/expr.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/detail/expr.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/detail/expr.hpp 2010-03-08 13:00:45 EST (Mon, 08 Mar 2010)
@@ -20,10 +20,10 @@
 #include <boost/type_traits.hpp>
 #include <boost/utility/enable_if.hpp>
 #include <boost/range.hpp>
-#include <boost/assign/list_of.hpp> // needed for assign_reference
 #include <boost/assign/auto_size/detail/has_static_size.hpp>
 #include <boost/assign/auto_size/detail/static_size.hpp>
 #include <boost/assign/auto_size/detail/assign_reference_copy.hpp>
+#include <boost/assign/auto_size/detail/assign_reference_rebind.hpp>
 #include <boost/assign/auto_size/detail/policy.hpp>
 #include <boost/assign/auto_size/detail/types.hpp>
 #include <boost/assign/auto_size/detail/expr_size.hpp>
@@ -42,6 +42,12 @@
 //
 // Acknowledgement: The idea of this class was developed in collaboration
 // with M.P.G
+//
+// To comply AMAP with the rest of the Boost.Assign framework, has method
+// range<int>() whose size must be specified explicitly. However, this defeats
+// the purpose of the 'auto_size' framework and incurrs a performance penalty,
+// so it is recommended to use a range concatenation tool such as boost::chain
+// in Boost.Range_ex.
 
 namespace boost{
 namespace assign{
@@ -281,7 +287,7 @@
 
     template<typename T>
     struct ref_rebind{
- typedef boost::assign_detail::assign_reference<T> type;
+ typedef boost::assign::detail::assign_reference_rebind<T> type;
     };
 
     // ---- first expr ---- //

Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/detail/has_copy_semantics.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/detail/has_copy_semantics.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/detail/has_copy_semantics.hpp 2010-03-08 13:00:45 EST (Mon, 08 Mar 2010)
@@ -20,6 +20,7 @@
     template<typename T> struct has_copy_semantics{};
     
     template< class T > struct assign_reference_copy;
+ template< class T > struct assign_reference_rebind;
     
     template<typename T>
     struct has_copy_semantics<
@@ -30,6 +31,11 @@
     struct has_copy_semantics<
             assign_reference_copy<T>
> : boost::mpl::bool_<true>{};
+
+ template<typename T>
+ struct has_copy_semantics<
+ assign_reference_rebind<T>
+ > : boost::mpl::bool_<false>{};
     
 }// detail
 }// assign

Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/detail/has_static_size.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/detail/has_static_size.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/detail/has_static_size.hpp 2010-03-08 13:00:45 EST (Mon, 08 Mar 2010)
@@ -9,28 +9,30 @@
 #ifndef BOOST_ASSIGN_DETAIL_AUTO_SIZE_HAS_STATIC_SIZE_ER_2010_HPP
 #define BOOST_ASSIGN_DETAIL_AUTO_SIZE_HAS_STATIC_SIZE_ER_2010_HPP
 #include <boost/mpl/bool.hpp>
+#include <boost/type_traits/detail/yes_no_type.hpp>
 
 namespace boost{
 namespace assign{
 namespace detail{
 namespace auto_size{
 
- // TODO
     template<typename T>
     struct has_static_size{
-/*
- typedef typename T::size_type size_type;
- typedef char yes;
- typedef char (&no)[2];
- typedef const size_type* sig;
-// typedef size_type (const T::*sig)();
-
- template<typename U,sig>
- struct sfinae { };
-
- template<typename U> static yes test(sfinae<U, &U::static_size> *);
- //template<typename U> static yes test(sfinae<U,&U::size> *);
- template<typename U> static no test(...);
+ typedef typename T::size_type size_type;
+ typedef typename type_traits::yes_type yes;
+ typedef typename type_traits::no_type no;
+ typedef const size_type* sig1;
+ typedef const size_type sig2; // for boost::array<>
+
+ template<typename U,sig1>
+ struct sfinae1 { };
+
+ template<typename U,sig2>
+ struct sfinae2 { };
+
+ //template<typename U> static yes test(sfinae1<U, &U::static_size> *);
+ template<typename U> static yes test(sfinae2<U, U::static_size> *);
+ template<typename U> static no test(...);
 
                 BOOST_STATIC_CONSTANT(
                 bool,
@@ -38,23 +40,7 @@
         );
         
         typedef boost::mpl::bool_<value> type;
-*/
    };
-}
-}
-}
-
- template<typename T,std::size_t N>
- struct array;
-
-namespace assign{
-namespace detail{
-namespace auto_size{
-
- // temporary fix
- template<typename T,std::size_t N>
- struct has_static_size<boost::array<T,N> > : boost::mpl::bool_<true>{};
-
 
 }// auto_size
 }// detail

Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/ref_list_of.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/ref_list_of.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/ref_list_of.hpp 2010-03-08 13:00:45 EST (Mon, 08 Mar 2010)
@@ -10,10 +10,7 @@
 #define BOOST_ASSIGN_AUTO_SIZE_REF_LIST_OF_ER_2010_HPP
 #include <boost/assign/auto_size/detail/expr.hpp>
 
-// Creates a collection of references whose functionality is that of
-// auto_size::array_interface<>. It can be used either as the rhs or lhs
-// of an assignment such as:
-// boost::fill(ref_list_of(a)(b)(c),0)
+// Returns a collection builder
 
 namespace boost{
 namespace assign{

Modified: sandbox/statistics/detail/assign/boost/assign/auto_size/ref_rebind_list_of.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/auto_size/ref_rebind_list_of.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/ref_rebind_list_of.hpp 2010-03-08 13:00:45 EST (Mon, 08 Mar 2010)
@@ -10,11 +10,7 @@
 #define BOOST_ASSIGN_AUTO_SIZE_REF_REBIND_LIST_OF_ER_2010_HPP
 #include <boost/assign/auto_size/detail/expr.hpp>
 
-// Creates a collection of references whose functionality is that of
-// auto_size::array_interface<>. Rebind semantics apply if the collection
-// is the lhs of an assignment:
-// cref_rebind_list_of(a)(b)(c).assign(d)
-// Unless this specific feature is needed, ref_list_of() is preferable.
+// Returns a collection builder with rebind semantics
 
 namespace boost{
 namespace assign{

Modified: sandbox/statistics/detail/assign/libs/assign/doc/revision_history.txt
==============================================================================
--- sandbox/statistics/detail/assign/libs/assign/doc/revision_history.txt (original)
+++ sandbox/statistics/detail/assign/libs/assign/doc/revision_history.txt 2010-03-08 13:00:45 EST (Mon, 08 Mar 2010)
@@ -1,5 +1,9 @@
 // Revision history:
 //
+// March 8, 2010 : Made array_interface derive from assign_detail::convert for
+// greater conformity with the rest of the library.
+// March 7, 2010 : Added assign_reference_rebind whose op= and swap have rebind
+// semantics.
 // March 6, 2010 : Added support for range insertion
 // March 4, 2010 : Created function template overloads to ref_list_of() etc.
 // that allow to specify a policy.

Modified: sandbox/statistics/detail/assign/libs/assign/example/ref_list_of.cpp
==============================================================================
--- sandbox/statistics/detail/assign/libs/assign/example/ref_list_of.cpp (original)
+++ sandbox/statistics/detail/assign/libs/assign/example/ref_list_of.cpp 2010-03-08 13:00:45 EST (Mon, 08 Mar 2010)
@@ -1,120 +1,281 @@
 //////////////////////////////////////////////////////////////////////////////
-// example::ref_list_of.cpp //
+// example::ref_list_of.h //
 // //
 // (C) Copyright 2010 Erwann Rogard //
 // Use, modification and distribution are subject to 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 <ostream>
+#include <boost/detail/workaround.hpp>
+#include <libs/assign/test/ref_list_of.h>
 #include <vector>
+#include <set>
+#include <list>
+#include <stack>
+#include <queue>
 #include <algorithm>
+#include <iostream>
 #include <boost/typeof/typeof.hpp>
-#include <boost/assign/auto_size/detail/has_static_size.hpp> // temporary
-#include <boost/assign/auto_size/ref_list_of.hpp> // temporary
-#include <boost/assign/auto_size/ref_csv.hpp>
-#include <boost/assign/auto_size/ref_rebind_csv.hpp>
-
-#include <boost/assign/list_of.hpp>
-#include <boost/range/algorithm/max_element.hpp>
-#include <libs/assign/example/ref_list_of.h>
+#include <boost/array.hpp>
+#include <boost/range.hpp>
+//#include <boost/range/chain.hpp>//Uncomment when in release
+#include <boost/assign/auto_size/ref_list_of.hpp>
+#include <boost/assign/auto_size/ref_rebind_list_of.hpp>
+#include <libs/assign/test/ref_list_of.h>
 
-void example_ref_list_of(std::ostream& os)
+template< class Range >
+void print( const Range& r )
 {
- os << "-> example_ref_listof : ";
- using namespace boost::assign;
- using namespace boost::assign::detail::auto_size;
- typedef std::vector<int> ints_;
- typedef boost::array<int,3> array_;
- array_ array;
-
- // Since the conversion operator calls begin() and end(), no need to test
- // these separately
-
- ints_ ints;
- {
- int a=1, b=2, c=3;
-
- {
- array.assign(-1);
- typedef boost::mpl::int_<3> K_;
- BOOST_AUTO(tmp,
- cref_list_of(a)(b)(c).range(array)
- );
-
- BOOST_ASSERT(tmp[0] == a);
- BOOST_ASSERT(tmp[1] == b);
- BOOST_ASSERT(tmp[2] == c);
- BOOST_ASSERT(tmp[3] == array[0]);
- BOOST_ASSERT(tmp[4] == array[1]);
- BOOST_ASSERT(tmp[5] == array[2]);
+ std::cout << "\n printing " << typeid(r).name() << " \n";
+ std::cout << "\n";
+
+ typedef typename boost::range_iterator<const Range>::type it_;
+
+ for(it_ i = r.begin(), e = r.end();
+ i !=e; ++i )
+ std::cout << " " << *i;
+}
 
- }
+template< class Range >
+void sort( const Range& r )
+{
+ std::cout << "\n sorting " << typeid(r).name() << " \n";
+ std::sort( r.begin(), r.end() );
+ print( r );
+}
 
- {
- ints.clear();
+template< class Range, class Pred >
+void sort( const Range& r, Pred pred )
+{
+ std::cout << "\n sorting " << typeid(r).name() << " \n";
+ std::sort( r.begin(), r.end(), pred );
+ print( r );
+}
 
- ints = cref_csv(a,b,3);
- BOOST_ASSERT(boost::size(ints) == 3);
- BOOST_ASSERT(ints[0] == a);
- BOOST_ASSERT(ints[1] == b);
- BOOST_ASSERT(ints[2] == c);
-
- }
+template< class Range >
+typename Range::const_iterator max_element( const Range& r )
+{
+ return std::max_element( r.begin(), r.end() );
+}
+
+
+template<typename C>
+void check_converter(C& elems,bool sorted = false){
+ using namespace boost::assign;
+ int a=1, b=5, c=3, d=4, e=2, f=9, g=0, h=7;
+ BOOST_AUTO(tmp,cref_list_of(a)(b)(c)(d)(e)(f)(g)(h));
+ elems = tmp;
+ elems == tmp;
+ elems >= tmp;
+ tmp == elems;
+ tmp <= elems;
+ typedef typename boost::range_iterator<const C>::type it_;
+ it_ it = boost::begin(elems);
+ if(!sorted){
+ BOOST_ASSERT(*it == a); ++it;
+ BOOST_ASSERT(*it == b); ++it;
+ BOOST_ASSERT(*it == c); ++it;
+ BOOST_ASSERT(*it == d); ++it;
+ BOOST_ASSERT(*it == e); ++it;
+ BOOST_ASSERT(*it == f); ++it;
+ BOOST_ASSERT(*it == g); ++it;
+ BOOST_ASSERT(*it == h); ++it;
+ BOOST_ASSERT(it == boost::end(elems));
+ }else{
+ BOOST_ASSERT(*it == 0); ++it;
+ BOOST_ASSERT(*it == 1); ++it;
+ BOOST_ASSERT(*it == 2); ++it;
+ BOOST_ASSERT(*it == 3); ++it;
+ BOOST_ASSERT(*it == 4); ++it;
+ BOOST_ASSERT(*it == 5); ++it;
+ BOOST_ASSERT(*it == 7); ++it;
+ BOOST_ASSERT(*it == 9); ++it;
+ BOOST_ASSERT(it == boost::end(elems));
+ }
+}
+
+void example_ref_list_of(std::ostream& os)
+{
+ os << "->example_ref_list_of : ";
+
+ using namespace boost::assign;
+ const int
+ a1 = 1, b1 = 5, c1 = 3,
+ d1 = 4, e1 = 2, f1 = 9,
+ g1 = 0, h1 = 7, i1 = 8;
+ // ---- Examples in the documentation
+ {
+ int a=a1, b=b1, c=c1, d=d1, e=e1, f=f1, g=g1, h=h1;
         {
- array.assign(-1);
- array = cref_csv(a,b,3);
- BOOST_ASSERT(array[0] == a);
- BOOST_ASSERT(array[1] == b);
- BOOST_ASSERT(array[2] == c);
+ int& max = *max_element( ref_list_of(a)(b)(c)(d)(e)(f)(g)(h) );
+ BOOST_ASSERT( max == f );
+ max = 8;
+ BOOST_ASSERT( f == 8 );
+ const int& const_max = *max_element(
+ cref_list_of(1)(5)(3)(d)(e)(f)(g)(h) );
+ BOOST_ASSERT( max == const_max );
         }
         {
- BOOST_AUTO(tmp,ref_csv(a,b,c));
- tmp.assign(0);
- BOOST_ASSERT(a == 0);
- BOOST_ASSERT(b == 0);
- BOOST_ASSERT(c == 0);
+ int a=a1, b=b1, c=c1, d=d1, e=e1, f=f1;
+ BOOST_AUTO(tmp1,ref_rebind_list_of(a)(b)(c));
+ BOOST_AUTO(tmp2,ref_rebind_list_of(d)(e)(f));
+ tmp1.swap(tmp2);
+ BOOST_ASSERT(tmp1[1]==e);
+ BOOST_ASSERT(tmp2[1]==b);
+
         }
     }
+ // ---- Copy semantics
+ { // As right operand (iterators + array)
+ int a=a1, d=d1, e=e1, f=f1, g=g1, h=h1;
+ BOOST_AUTO(tmp,cref_list_of(1)(5)(3)(d)(e)(f)(g)(h));
+ BOOST_AUTO(it,boost::begin(tmp));
+ BOOST_ASSERT(*it == a); it = boost::next(it,7);
+ BOOST_ASSERT(*it == h); ++it;
+ BOOST_ASSERT(it == boost::end(tmp));
+ BOOST_ASSERT( tmp.size() == 8 );
+ BOOST_ASSERT( tmp.empty() == false );
+ BOOST_ASSERT( tmp[0] == a );
+ BOOST_ASSERT( tmp[7] == h );
+ BOOST_ASSERT( tmp.front() == a );
+ BOOST_ASSERT( tmp.back() == h );
+ }
+ { // As left operand (iterators)
+ int a, b, c,
+ d, e, f,
+ g, h, i;
+ BOOST_AUTO(tmp1,cref_list_of
+ (a1)(b1)(c1)
+ (d1)(e1)(f1)
+ (g1)(h1)(i1));
+ BOOST_AUTO(tmp2,ref_list_of
+ (a)(b)(c)
+ (d)(e)(f)
+ (g)(h)(i));
+ std::copy(boost::begin(tmp1),boost::end(tmp1),boost::begin(tmp2));
+ BOOST_ASSERT(a == a1);
+ BOOST_ASSERT(b == b1);
+ BOOST_ASSERT(c == c1);
+ BOOST_ASSERT(d == d1);
+ BOOST_ASSERT(e == e1);
+ BOOST_ASSERT(f == f1);
+ BOOST_ASSERT(g == g1);
+ BOOST_ASSERT(h == h1);
+ BOOST_ASSERT(i == i1);
+ }
+ { // As left operand (array)
+ int a=a1, b=b1, c=c1,
+ d=d1, e=e1, f=f1,
+ g=g1, h=h1, i=i1;
+ BOOST_AUTO(tmp1,ref_list_of(a)(b)(c));
+ BOOST_AUTO(tmp2,ref_list_of(d)(e)(f));
+ BOOST_AUTO(tmp3,ref_list_of(g)(h)(i));
+ tmp1.swap(tmp2);
+ BOOST_ASSERT( a == d1 );
+ BOOST_ASSERT( b == e1 );
+ BOOST_ASSERT( c == f1 );
+ BOOST_ASSERT( d == a1 );
+ BOOST_ASSERT( e == b1 );
+ BOOST_ASSERT( f == c1 );
+ tmp3.assign(0);
+ BOOST_ASSERT( g == 0 );
+ BOOST_ASSERT( h == 0 );
+ BOOST_ASSERT( i == 0 );
+ }
+ // ---- Rebind semantics
+ { // As left operand
+ int a=a1, b=b1, c=c1,
+ d=d1, e=e1, f=f1,
+ g=g1, h=h1, i=i1;
+ BOOST_AUTO(tmp1,ref_rebind_list_of(a)(b)(c));
+ BOOST_AUTO(tmp2,ref_rebind_list_of(d)(e)(f));
+ BOOST_AUTO(tmp3,cref_rebind_list_of(g)(h)(i));
+ tmp1.swap(tmp2);
+ BOOST_ASSERT( tmp1[0] == d );
+ BOOST_ASSERT( tmp1[1] == e );
+ BOOST_ASSERT( tmp1[2] == f );
+ BOOST_ASSERT( tmp2[0] == a );
+ BOOST_ASSERT( tmp2[1] == b );
+ BOOST_ASSERT( tmp2[2] == c );
+ BOOST_ASSERT( a == a1 );
+ BOOST_ASSERT( b == b1 );
+ BOOST_ASSERT( c == c1 );
+ BOOST_ASSERT( d == d1 );
+ BOOST_ASSERT( e == e1 );
+ BOOST_ASSERT( f == f1 );
+ tmp3.assign(d);
+ BOOST_ASSERT( tmp3[0] == d );
+ BOOST_ASSERT( tmp3[0] == d );
+ BOOST_ASSERT( tmp3[0] == d );
+ BOOST_ASSERT( g == g1 );
+ BOOST_ASSERT( h == h1 );
+ BOOST_ASSERT( i == i1 );
+ }
+ // ---- Concatenate ranges
+ {
+ boost::array<int,4> array; array.assign(-1);
+ int a=a1, b=b1, c=c1;
+
+ BOOST_ASSERT(boost::size(cref_list_of(a)(b)(c).range(array))==7u);
+ // Uncomment when range_ex is in the release
+ //BOOST_ASSERT(
+ // boost::size(
+ // boost::chain(
+ // cref_list_of(a)(b)(c),
+ // array
+ // )
+ // )== 7u
+ //);
+ }
+ // ---- Range conversion
     {
- // ref_rebind_csv
         {
- int a=1, b=2, c=3;
-
- {
- int d = 4;
-
- BOOST_AUTO(
- max,
- *boost::max_element(
- ref_rebind_csv(a,b,c)
- )
- );
- max = d;
- d = 5;
- BOOST_ASSERT(max == 5);
- }
-
- ints.clear();
- BOOST_AUTO(tmp,cref_rebind_csv(a,b,c));
- {
- ints = tmp;
- BOOST_ASSERT(ints[0] == a);
- BOOST_ASSERT(ints[1] == b);
- BOOST_ASSERT(ints[2] == c);
- }
- int d = 4;
- tmp.assign(d);
- d = 5;
- {
- ints = tmp;
- BOOST_ASSERT(ints[0] == d);
- BOOST_ASSERT(ints[1] == d);
- BOOST_ASSERT(ints[2] == d);
- }
- }
+ std::list<int> elems;
+ check_converter(elems);
+ }
+ {
+ std::set<int> elems;
+ check_converter(elems,true);
+ }
+ {
+ std::vector<int> elems;
+ check_converter(elems);
+ }
+ {
+ boost::array<int,8> elems;
+ check_converter(elems);
+ }
     }
-
- os << "<- " << std::endl;
-
+ // ---- Adapters
+ {
+ {
+ std::stack<int> elems;
+ int a=a1, b=b1, c=c1, d=d1, e=e1, f=f1, g=g1, h=h1;
+ elems = cref_list_of(a)(b)(c)(d)(e)(f)(g)(h).to_adapter();
+ BOOST_ASSERT(elems.top() == h); elems.pop();
+ BOOST_ASSERT(elems.top() == g); elems.pop();
+ BOOST_ASSERT(elems.top() == f); elems.pop();
+ BOOST_ASSERT(elems.top() == e); elems.pop();
+ BOOST_ASSERT(elems.top() == d); elems.pop();
+ BOOST_ASSERT(elems.top() == c); elems.pop();
+ BOOST_ASSERT(elems.top() == b); elems.pop();
+ BOOST_ASSERT(elems.top() == a); elems.pop();
+ BOOST_ASSERT(elems.empty() == true);
+ }
+ {
+ std::queue<int> elems;
+ int a=a1, b=b1, c=c1, d=d1, e=e1, f=f1, g=g1, h=h1;
+ elems = cref_list_of(a)(b)(c)(d)(e)(f)(g)(h).to_adapter();
+ BOOST_ASSERT(elems.front() == a); elems.pop();
+ BOOST_ASSERT(elems.front() == b); elems.pop();
+ BOOST_ASSERT(elems.front() == c); elems.pop();
+ BOOST_ASSERT(elems.front() == d); elems.pop();
+ BOOST_ASSERT(elems.front() == e); elems.pop();
+ BOOST_ASSERT(elems.front() == f); elems.pop();
+ BOOST_ASSERT(elems.front() == g); elems.pop();
+ BOOST_ASSERT(elems.front() == h); elems.pop();
+ BOOST_ASSERT(elems.empty() == true);
+ }
+ }
+ os << "<-" << std::endl;
 }

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-08 13:00:45 EST (Mon, 08 Mar 2010)
@@ -1,13 +1,15 @@
 #include <iostream>
 #include <libs/assign/example/ref_list_of.h>
 //#include <libs/assign/test/speed.h>
-#include <libs/assign/test/speed2.h>
+//#include <libs/assign/test/speed2.h>
+//#include <libs/assign/test/ref_list_of.h>
 
 int main (int argc, char * const argv[]) {
 
     example_ref_list_of(std::cout);
     //test_speed(std::cout);
- test_speed2(std::cout);
+ //test_speed2(std::cout);
+ //check_ref_list_of();
 
     return 0;
 

Modified: sandbox/statistics/detail/assign/libs/assign/test/static_list_of_auto_size.cpp
==============================================================================
--- sandbox/statistics/detail/assign/libs/assign/test/static_list_of_auto_size.cpp (original)
+++ sandbox/statistics/detail/assign/libs/assign/test/static_list_of_auto_size.cpp 2010-03-08 13:00:45 EST (Mon, 08 Mar 2010)
@@ -19,10 +19,18 @@
 # pragma warn -8057 // unused argument argc/argv in Boost.Test
 #endif
 
+#include <vector>
+#include <set>
+#include <list>
+#include <stack>
+#include <queue>
 #include <algorithm>
 #include <iostream>
-#include <boost/assign/auto_size/ref_list_of.hpp>
+#include <boost/typeof/typeof.hpp>
 #include <boost/array.hpp>
+#include <boost/range.hpp>
+#include <boost/assign/auto_size/ref_list_of.hpp>
+#include <boost/assign/auto_size/ref_rebind_list_of.hpp>
 #include <boost/test/test_tools.hpp>
 
 template< class Range >
@@ -65,36 +73,151 @@
     return std::max_element( r.begin(), r.end() );
 }
 
-void check_static_list_of_auto_size()
+
+template<typename C>
+void check_converter(C& elems){
+ using namespace boost::assign;
+ int a=1, b=5, c=3, d=4, e=2, f=9, g=0, h=7;
+ BOOST_AUTO(tmp,cref_list_of(a)(b)(c)(d)(e)(f)(g)(h));
+ elems = tmp;
+ elems == tmp;
+ typedef typename boost::range_iterator<const C>::type it_;
+ it_ it = boost::begin(elems);
+ BOOST_CHECK_EQUAL(*it,a); ++it;
+ BOOST_CHECK_EQUAL(*it,b); ++it;
+ BOOST_CHECK_EQUAL(*it,c); ++it;
+ BOOST_CHECK_EQUAL(*it,d); ++it;
+ BOOST_CHECK_EQUAL(*it,e); ++it;
+ BOOST_CHECK_EQUAL(*it,f); ++it;
+ BOOST_CHECK_EQUAL(*it,g); ++it;
+ BOOST_CHECK_EQUAL(*it,h); ++it;
+}
+
+void check_ref_list_of()
 {
     using namespace boost::assign;
         {
- BOOST_CHECK( cref_list_of( 1 )( 2 )( 3 )( 4 ).size() == 4 );
+ int a=1, b=5, c=3, d=4, e=2, f=9, g=0, h=7;
+ BOOST_AUTO(tmp,cref_list_of(1)(5)(3)(d)(e)(f)(g)(h));
+ BOOST_AUTO(it,boost::begin(tmp));
+ BOOST_CHECK_EQUAL(*it,a); it = boost::next(it,7);
+ BOOST_CHECK_EQUAL(*it,h); ++it;
+ BOOST_CHECK_EQUAL(it,boost::end(tmp));
+ BOOST_CHECK_EQUAL( tmp.size(), 8 );
+ BOOST_CHECK_EQUAL( tmp.empty(), false );
+ BOOST_CHECK_EQUAL( tmp[0], a );
+ BOOST_CHECK_EQUAL( tmp[7], h );
+ BOOST_CHECK_EQUAL( tmp.front(), a );
+ BOOST_CHECK_EQUAL( tmp.back(), h );
+ }
+ {
+ int a, b, c, d, e, f, g, h, i;
+ {
+ BOOST_AUTO(tmp,ref_list_of(a)(b)(c)(d)(e)(f)(g));
+ //ref_list_of(a)(b)(c)(d)(e)(f)(g) = cref_list_of(1)(5)(3)(4)(2)(9)(0)(7);
+ BOOST_CHECK_EQUAL(a,1);
+ BOOST_CHECK_EQUAL(h,7);
+ }
+ {
+ BOOST_AUTO(tmp,ref_list_of(a)(b)(c));
+ tmp.front() = d;
+ tmp[1] = e;
+ tmp.back() = f;
+ BOOST_CHECK_EQUAL( a, d );
+ BOOST_CHECK_EQUAL( b, e );
+ BOOST_CHECK_EQUAL( c, f );
+ }
+ {
+ BOOST_AUTO(tmp1,ref_list_of(a)(b)(c));
+ BOOST_AUTO(tmp2,ref_list_of(g)(h)(i));
+ tmp1.assign(0);
+ BOOST_CHECK_EQUAL( a, 0 );
+ BOOST_CHECK_EQUAL( c, 0 );
+ BOOST_CHECK_EQUAL( c, 0 );
+ // TODO. Currently ambiguous
+ //BOOST_CHECK_EQUAL(
+ // (ref_list_of(a)(b)(c) == ref_list_of(g)(h)(i)) ,false);
+ //BOOST_CHECK_EQUAL(
+ // ref_list_of(a)(b)(c) == cref_list_of(0)(0)(0) ,true);
+ //BOOST_CHECK_EQUAL(
+ // ref_list_of(a)(b)(c) < ref_list_of(g)(h)(i) ,false);
+ //BOOST_CHECK_EQUAL(
+ // ref_list_of(a)(b)(c) > ref_list_of(g)(h)(i) ,true);
+ }
+ }
+ { // ref_rebind_list_of
+ int a=1, b=5, c=3, d=4, e=2, f=9, g=0, h=7, i=9;
+ BOOST_AUTO(tmp,ref_rebind_list_of(a)(b)(c));
+ tmp[0] = d;
+ tmp[1] = e;
+ tmp[2] = f;
+ BOOST_CHECK_EQUAL( a, d );
+ BOOST_CHECK_EQUAL( b, e );
+ BOOST_CHECK_EQUAL( c, f );
+ {
+ BOOST_AUTO(tmp,ref_rebind_list_of(d)(e)(f));
+ tmp[0] = g;
+ tmp[1] = h;
+ tmp[2] = i;
+ BOOST_CHECK_EQUAL( a, g );
+ BOOST_CHECK_EQUAL( b, h );
+ BOOST_CHECK_EQUAL( c, i );
+ }
+ // TODO swap
+ }
+ {
+ {
+ std::list<int> elems;
+ check_converter(elems);
+ }
+ {
+ std::set<int> elems;
+ check_converter(elems);
+ }
+ {
+ std::vector<int> elems;
+ check_converter(elems);
+ }
+ {
+ boost::array<int,8> elems;
+ check_converter(elems);
+ }
+ {
+ boost::array<int,1> elems;
+ check_converter(elems);
+ }
+ {
+ std::stack<int> elems;
+ bool fifo = false;
+ int a=1, b=5, c=3, d=4, e=2, f=9, g=0, h=7;
+ elems = cref_list_of(a)(b)(c)(d)(e)(f)(g)(h).to_adapter();
+ int bench = fifo?a:h;
+ BOOST_CHECK_EQUAL(elems.top(),bench); elems.pop(); bench = fifo?b:g;
+ BOOST_CHECK_EQUAL(elems.top(),bench); elems.pop(); bench = fifo?c:f;
+ BOOST_CHECK_EQUAL(elems.top(),bench); elems.pop(); bench = fifo?d:e;
+ BOOST_CHECK_EQUAL(elems.top(),bench); elems.pop(); bench = fifo?e:d;
+ BOOST_CHECK_EQUAL(elems.top(),bench); elems.pop(); bench = fifo?f:c;
+ BOOST_CHECK_EQUAL(elems.top(),bench); elems.pop(); bench = fifo?f:b;
+ BOOST_CHECK_EQUAL(elems.top(),bench); elems.pop(); bench = fifo?h:a;
+ }
+ {
+ std::queue<int> elems;
+ bool fifo = true;
+ int a=1, b=5, c=3, d=4, e=2, f=9, g=0, h=7;
+ elems = cref_list_of(a)(b)(c)(d)(e)(f)(g)(h).to_adapter();
+ int bench = fifo?a:h;
+ BOOST_CHECK_EQUAL(elems.front(),bench); elems.pop(); bench = fifo?b:g;
+ BOOST_CHECK_EQUAL(elems.front(),bench); elems.pop(); bench = fifo?c:f;
+ BOOST_CHECK_EQUAL(elems.front(),bench); elems.pop(); bench = fifo?d:e;
+ BOOST_CHECK_EQUAL(elems.front(),bench); elems.pop(); bench = fifo?e:d;
+ BOOST_CHECK_EQUAL(elems.front(),bench); elems.pop(); bench = fifo?f:c;
+ BOOST_CHECK_EQUAL(elems.front(),bench); elems.pop(); bench = fifo?f:b;
+ BOOST_CHECK_EQUAL(elems.front(),bench); elems.pop(); bench = fifo?h:a;
+ }
     
- int a=1,b=5,c=3,d=4,e=2,f=9,g=0,h=7;
-
- int& max = *max_element( ref_list_of(a)(b)(c)(d)(e)(f)(g)(h) );
- BOOST_CHECK_EQUAL( max, f );
- max = 8;
- BOOST_CHECK_EQUAL( f, 8 );
- const int& const_max = *max_element(
- cref_list_of(a)(b)(c)(d)(e)(f)(g)(h)
- );
- BOOST_CHECK_EQUAL( max, const_max );
-
- print( ref_list_of(a)(b)(c)(d)(e)(f)(g)(h) );
- print( cref_list_of(a)(b)(c)(d)(e)(f)(g)(h) );
-
- boost::array<int,4> array = cref_list_of(1)(2)(3)(4);
-
- BOOST_CHECK_EQUAL( array[0], 1 );
- BOOST_CHECK_EQUAL( array[3], 4 );
- //
- //print( cref_list_of( "foo" )( "bar" )( "foobar" ) );
- //
     }
 }
-
+/*
 #include <boost/test/unit_test.hpp>
 using boost::unit_test::test_suite;
 
@@ -106,3 +229,4 @@
 
     return test;
 }
+*/
\ No newline at end of file


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