Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59648 - in sandbox/statistics/detail/assign/boost/assign/auto_size: . detail
From: erwann.rogard_at_[hidden]
Date: 2010-02-11 15:16:56


Author: e_r
Date: 2010-02-11 15:16:56 EST (Thu, 11 Feb 2010)
New Revision: 59648
URL: http://svn.boost.org/trac/boost/changeset/59648

Log:
add
Added:
   sandbox/statistics/detail/assign/boost/assign/auto_size/
   sandbox/statistics/detail/assign/boost/assign/auto_size/detail/
   sandbox/statistics/detail/assign/boost/assign/auto_size/detail/assign_refence_copy.hpp (contents, props changed)
   sandbox/statistics/detail/assign/boost/assign/auto_size/detail/auto_size.hpp (contents, props changed)

Added: sandbox/statistics/detail/assign/boost/assign/auto_size/detail/assign_refence_copy.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/detail/assign_refence_copy.hpp 2010-02-11 15:16:56 EST (Thu, 11 Feb 2010)
@@ -0,0 +1,63 @@
+//////////////////////////////////////////////////////////////////////////////
+// assign::detail::assign_reference_copy.hpp //
+// //
+// (C) Copyright 2010 M.P.G //
+// 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) //
+//////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_ASSIGN_DETAIL_ASSIGN_REFERENCE_COPY_MPG_2010_HPP
+#define BOOST_ASSIGN_DETAIL_ASSIGN_REFERENCE_COPY_MPG_2010_HPP
+
+namespace boost{
+namespace assign_detail{
+
+ // This is a reference wrapper whose assignment operator copies the value of
+ // the rhs to the object pointed to.
+ //
+ // This is in contrast to assign_reference whose operator= rebinds the
+ // address of the internal pointer. To that effect,here, call rebind()
+ template< class T >
+ struct assign_reference_copy
+ {
+ assign_reference_copy()
+ { /* intentionally empty */ }
+
+ assign_reference_copy( T& r ) : ref_(&r)
+ { }
+
+ void operator=( const T& r )
+ {
+ *ref_ = r;
+ }
+
+ operator T&() const
+ {
+ return *ref_;
+ }
+
+ void swap( assign_reference_copy& r )
+ {
+ std::swap( *ref_, *r.ref_ );
+ }
+
+ T& get_ref() const
+ {
+ return *ref_;
+ }
+
+ void rebind( T & r )
+ {
+ ref_ = &r;
+ }
+
+ private:
+ T* ref_;
+
+ };
+
+}// assign_detail
+}// boost
+
+#endif
+

Added: sandbox/statistics/detail/assign/boost/assign/auto_size/detail/auto_size.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/detail/auto_size.hpp 2010-02-11 15:16:56 EST (Thu, 11 Feb 2010)
@@ -0,0 +1,207 @@
+//////////////////////////////////////////////////////////////////////////////
+// assign::detail::ref_list_of_auto_size_copy_rebind.hpp //
+// //
+// (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) //
+//////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_ASSIGN_DETAIL_REF_LIST_OF_AUTO_SIZE_COPY_REBIND_ER_2010_HPP
+#define BOOST_ASSIGN_DETAIL_REF_LIST_OF_AUTO_SIZE_COPY_REBIND_ER_2010_HPP
+#include <boost/mpl/void.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/equal_to.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/array.hpp>
+#include <boost/range.hpp>
+#include <boost/assign/list_of.hpp> // needed for assign_referene
+#include <boost/assign/detail/assign_value.hpp>
+
+// This is the implementation behind ref_list_of() and ref_copy_list_of().
+//
+// The motivation for this class was to improve upon ref_list_of<int>(), by
+// deducing the number of arguments at compile time, and allowing for either
+// of copy or rebind semantics, in case it is used as the lhs of an assignment;
+// the former (copy) being both safer and more common than the latter (rebind).
+//
+// Acknowledgement: The idea of this class was developed in collaboration
+// with M.P.G
+//
+// Revision history:
+// Feb 9, 2010 :
+// - Added copy semantics.
+// - The temporary array in the conversion operator is now assigned by calling
+// begin() and end() rather than write_to_array() to ensure consistency of
+// side effect when assigning under rebind semantics. Negligible loss in
+// performance
+// Feb 5, 2010 : First version. rebind semantics.
+
+namespace boost{
+namespace assign{
+namespace detail{
+namespace auto_size{
+
+ typedef boost::mpl::void_ top_;
+
+ // Rebind semantics
+ template<typename T>
+ struct ref_bind{
+ typedef boost::assign_detail::assign_reference<T> type;
+ };
+
+ // Copy semantics
+ template<typename T>
+ struct ref_value{
+ typedef boost::assign_detail::assign_reference_copy<T> type;
+ };
+
+ template<typename T,int N,template<typename> class Ref>
+ struct ref_array{
+ typedef boost::array<typename Ref<T>::type,N> type;
+ };
+
+ template<typename L,typename T,int N,template<typename> class Ref>
+ struct expr;
+
+ template<typename E,typename T,int N,template<typename> class Ref>
+ struct next{
+ typedef expr<E,T,N,Ref> expr_;
+ typedef expr<expr_,T,N+1,Ref> type;
+ };
+
+ template<typename E,typename T,int N,template<typename> class Ref>
+ class expr{
+ typedef boost::mpl::int_<N> int_n_;
+ typedef boost::mpl::int_<1> int_1_;
+ typedef typename Ref<T>::type ref_;
+
+ public:
+ typedef typename boost::mpl::equal_to<int_n_,int_1_>::type is_first_;
+ typedef typename boost::mpl::if_<is_first_,E,E&>::type previous_;
+ typedef typename ref_array<T,N,Ref>::type ref_array_;
+ typedef typename next<E,T,N,Ref>::type next_;
+
+ previous_ previous;
+ ref_ ref;
+
+ expr(T& t):ref(t){} // only for N == 1
+ expr(E& p,T& t):previous(p),ref(t){}
+
+ typedef next_ result_type;
+ next_ operator()(T& t){ return next_(*this,t); }
+
+ template<typename T1>
+ operator boost::array<T1,N>(){
+ 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()
+ {
+ return C(
+ boost::begin(this->ref_array()),
+ boost::end(this->ref_array())
+ );
+ }
+
+ // -------- as container ---- //
+
+ typedef ref_ value_type;
+ typedef typename boost::range_iterator<ref_array_>::type iterator;
+ typedef typename boost::range_iterator<
+ const ref_array_>::type const_iterator;
+ typedef typename boost::range_size<ref_array_>::type size_type;
+ typedef typename boost::range_difference<
+ ref_array_>::type difference_type;
+
+ iterator begin()
+ {
+ return boost::begin(this->ref_array());
+ }
+ iterator end()
+ {
+ this->alloc_if();
+ return boost::end(this->ref_array());
+ }
+ size_type size() const
+ {
+ return ref_array_::size();
+ }
+ bool empty() const
+ {
+ return !(this->size());
+ }
+
+ private:
+ void alloc(){
+ this->ptr = smart_ptr_(new ref_array_);
+ write_to_array(*this->ptr,*this);
+ }
+
+ void alloc_if(){
+ if(!this->ptr){
+ return this->alloc();
+ }
+ }
+
+ ref_array_& ref_array(){
+ this->alloc_if();
+ return (*this->ptr);
+ }
+
+ typedef boost::shared_ptr<ref_array_> smart_ptr_;
+ smart_ptr_ ptr;
+
+ };
+
+ typedef boost::mpl::bool_<false> false_;
+ typedef boost::mpl::bool_<true> true_;
+
+ template<typename A,typename E,typename T,int N,
+ template<typename> class Ref>
+ void write_to_array(A& a,expr<E,T,N,Ref>& e){
+ typedef expr<E,T,N,Ref> expr_;
+ typedef typename expr_::is_first_ exit_;
+ write_to_array(a,e,exit_());
+ }
+
+ template<typename A,typename E,typename T,int N,
+ template<typename> class Ref>
+ void write_to_array(A& a,expr<E,T,N,Ref>& e,false_ /*exit*/){
+ a[N-1] = e.ref;
+ write_to_array(a,e.previous);
+ }
+
+ template<typename A,typename E,typename T,int N,
+ template<typename> class Ref>
+ void write_to_array(A& a,expr<E,T,N,Ref>& e,true_ /*exit*/){
+ a[N-1] = e.ref;
+ }
+
+ template<typename T>
+ struct copy_first{
+ typedef detail::auto_size::expr<
+ detail::auto_size::top_,T,1,ref_value> type;
+ };
+
+ template<typename T>
+ struct rebind_first{
+ typedef detail::auto_size::expr<
+ detail::auto_size::top_,T,1,ref_bind> type;
+ };
+
+}// auto_size
+}// detail
+}// assign
+}// boost
+
+#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