Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60661 - in sandbox/statistics/detail/assign/boost/assign/auto_size: array comparison_op
From: erwann.rogard_at_[hidden]
Date: 2010-03-16 19:13:48


Author: e_r
Date: 2010-03-16 19:13:47 EDT (Tue, 16 Mar 2010)
New Revision: 60661
URL: http://svn.boost.org/trac/boost/changeset/60661

Log:
m
Added:
   sandbox/statistics/detail/assign/boost/assign/auto_size/array/converter.hpp (contents, props changed)
   sandbox/statistics/detail/assign/boost/assign/auto_size/comparison_op/
   sandbox/statistics/detail/assign/boost/assign/auto_size/comparison_op/completed_policy.hpp (contents, props changed)
   sandbox/statistics/detail/assign/boost/assign/auto_size/comparison_op/crtp.hpp (contents, props changed)
   sandbox/statistics/detail/assign/boost/assign/auto_size/comparison_op/range.hpp (contents, props changed)

Added: sandbox/statistics/detail/assign/boost/assign/auto_size/array/converter.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/array/converter.hpp 2010-03-16 19:13:47 EDT (Tue, 16 Mar 2010)
@@ -0,0 +1,86 @@
+//////////////////////////////////////////////////////////////////////////////
+// assign::detail::array::converter.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_AUTO_SIZE_DETAIL_ARRAY_CONVERTER_ER_2010_HPP
+#define BOOST_ASSIGN_AUTO_SIZE_DETAIL_ARRAY_CONVERTER_ER_2010_HPP
+#include <boost/assign/list_of.hpp> // for assign_detail::converter
+#include <boost/assign/auto_size/comparison_op/range.hpp>
+
+namespace boost{
+namespace assign{
+namespace detail{
+namespace auto_size{
+
+ // Forwards to assign_detail::conveter<> for all but operators, allowing
+ // Op (converter<> ,converter<>)
+ // in addition to the existing feature
+ // Op( converter<> , Range)
+ // etc.
+ template< typename T, typename I >
+ class converter
+ : protected boost::assign_detail::converter<converter<T,I>,I>
+ ,public range_comparison_op::base_of< converter<T,I> >::type
+ {
+ typedef boost::assign_detail::converter<converter<T,I>,I> impl_;
+
+ impl_& impl(){ return (*this); }
+ const impl_& impl()const{ return (*this); }
+
+ public:
+ typedef typename impl_::iterator iterator;
+ typedef typename impl_::const_iterator const_iterator;
+
+ iterator begin() const
+ {
+ return this->impl().begin();
+ }
+
+ iterator end() const
+ {
+ return this->impl().end();
+ }
+
+ template< class Container >
+ Container convert_to_container() const
+ {
+ return this->impl().convert_to_container();
+ }
+
+ template< class Container >
+ Container to_container( Container& c ) const
+ {
+ return this->impl().to_container();
+ }
+
+ // // adaptor_converter is private.
+ //adapter_converter to_adapter() const
+ //{
+ // return this->impl().to_adapter();
+ //}
+
+ template< class Adapter >
+ Adapter to_adapter( Adapter& a ) const
+ {
+ return this->impl().to_adapter();
+ }
+
+ template< class Array >
+ Array to_array( Array& a ) const
+ {
+ return this->impl().to_array();
+ }
+
+ };
+
+
+}// auto_size
+}// detail
+}// assign
+}// boost
+
+#endif

Added: sandbox/statistics/detail/assign/boost/assign/auto_size/comparison_op/completed_policy.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/comparison_op/completed_policy.hpp 2010-03-16 19:13:47 EDT (Tue, 16 Mar 2010)
@@ -0,0 +1,53 @@
+//////////////////////////////////////////////////////////////////////////////
+// assign::detail::comparison_op::completed_policy.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_COMPARISON_OP_COMPLETED_POLICY_ER_2010_HPP
+#define BOOST_ASSIGN_DETAIL_COMPARISON_OP_COMPLETED_POLICY_ER_2010_HPP
+
+namespace boost{
+namespace assign{
+namespace detail{
+namespace comparison_op{
+
+ // If P is a 'fundamental policy' i.e. it defines
+ // P::equal(l,r)
+ // P::less(l,r)
+ // then Q = completed_policy<P> defines, in addition to those above,
+ // Q::not_equal(l,r)
+ // Q::greater(l,r)
+ // Q::less_equal(l,r)
+ // Q::greater_equal(l,r)
+ template<typename P>
+ struct completed_policy : P{
+ template<typename L,typename R>
+ static bool not_equal(const L& l,const R& r){
+ return !(P::equal(l,r));
+ }
+ template<typename L,typename R>
+ static bool less_or_equal(const L& l,const R& r){
+ return (P::less(l,r)) || (P::equal(l,r));
+ }
+
+ template<typename L,typename R>
+ static bool greater(const L& l,const R& r){
+ return !(less_or_equal(l,r));
+ }
+
+ template<typename L,typename R>
+ static bool greater_or_equal(const L& l,const R& r){
+ return !(P::less(l,r));
+ }
+
+ };
+
+}// comparison_op
+}// detail
+}// assign
+}// boost
+
+#endif

Added: sandbox/statistics/detail/assign/boost/assign/auto_size/comparison_op/crtp.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/comparison_op/crtp.hpp 2010-03-16 19:13:47 EDT (Tue, 16 Mar 2010)
@@ -0,0 +1,200 @@
+//////////////////////////////////////////////////////////////////////////////
+// assign::detail::comparison_op::crtp.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_COMPARISON_OP_CRTP_ER_2010_HPP
+#define BOOST_ASSIGN_DETAIL_COMPARISON_OP_CRTP_ER_2010_HPP
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/equal_to.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/eval_if.hpp>
+#include <boost/type_traits/is_base_of.hpp>
+#include <boost/type_traits/detail/yes_no_type.hpp>
+
+namespace boost{
+namespace assign{
+namespace detail{
+namespace comparison_op{
+
+// Source:
+// http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/389d8fe278ef0b13#
+
+ // If D inherits from crtp<D,P>, its comparison operators will forward to
+ // P::equal(l,r)
+ // P::less(l,r)
+ // P::greater(l,r)
+ // P::not_equal(l,r)
+ // P::less_equal(l,r)
+ // P::greater_equal(l,r)
+ // where l and r are two objects of types L and R, such that either L or R,
+ // or both, derive from crtp<>.
+ template<typename D,typename P>
+ struct crtp{
+ crtp(){}
+
+ struct comparison_op_traits{
+ typedef P policy_;
+ typedef D derived_;
+ };
+ };
+
+namespace traits{
+
+ template<typename T>
+ struct policy_of{
+ typedef typename T::comparison_op_traits::policy_ type;
+ };
+
+ template<typename T>
+ struct derived_of{
+ typedef typename T::comparison_op_traits::derived_ type;
+ };
+
+ template<typename T>
+ struct has_traits{
+ typedef typename type_traits::yes_type yes;
+ typedef typename type_traits::no_type no;
+
+ template<typename U> static yes test(typename U::comparison_op_traits*);
+ template<typename U> static no test(...);
+
+ BOOST_STATIC_CONSTANT( bool,
+ value = sizeof( test<T>(0) ) == sizeof(yes) );
+ typedef boost::mpl::bool_<value> type;
+ };
+
+ template<typename T>
+ struct is_base_of_impl : boost::is_base_of<
+ crtp<
+ typename derived_of<T>::type,
+ typename policy_of<T>::type
+ >,
+ T
+ >{};
+
+ template<typename T>
+ struct is_base_of : boost::mpl::eval_if< // left-to-right evaluation
+ traits::has_traits<T>,
+ traits::is_base_of_impl<T>,
+ boost::mpl::identity< boost::mpl::bool_<false> >
+ >{};
+
+ template<typename T,bool value>
+ struct is_base_of_equal_to : boost::mpl::equal_to<
+ typename traits::is_base_of<T>::type,
+ boost::mpl::bool_<value>
+ >{};
+
+ template<typename D1,bool value1,typename D2,bool value2>
+ struct are_bases_of_equal_to : boost::mpl::and_<
+ typename traits::is_base_of_equal_to<D1,value1>::type,
+ typename traits::is_base_of_equal_to<D2,value2>::type
+ >{};
+
+}//traits
+namespace forward{
+
+ struct equal{
+ template<typename P,typename L,typename R>
+ static bool call(const L& l,const R& r){
+ return (P::equal(l,r));
+ }
+ };
+
+ struct not_equal{
+ template<typename P,typename L,typename R>
+ static bool call(const L& l,const R& r){
+ return (P::not_equal(l,r));
+ }
+ };
+
+ struct less{
+ template<typename P,typename L,typename R>
+ static bool call(const L& l,const R& r){
+ return (P::less(l,r));
+ }
+ };
+
+ struct greater{
+ template<typename P,typename L,typename R>
+ static bool call(const L& l,const R& r){
+ return (P::greater(l,r));
+ }
+ };
+
+ struct less_or_equal_to{
+ template<typename P,typename L,typename R>
+ static bool call(const L& l,const R& r){
+ return (P::less_or_equal_to(l,r));
+ }
+ };
+
+ struct greater_or_equal_to{
+ template<typename P,typename L,typename R>
+ static bool call(const L& l,const R& r){
+ return (P::greater_or_equal_to(l,r));
+ }
+ };
+
+}//forward
+
+#define BOOST_ASSIGN_DETAIL_COMPARISON_OP(SYMB,OP) \
+ template<typename L,typename R> \
+ typename boost::enable_if_c< \
+ traits::are_bases_of_equal_to<L,true,R,false>::value, \
+ bool \
+ >::type \
+ operator SYMB (const L& l,const R& r){ \
+ typedef typename traits::policy_of<L>::type policy_; \
+ typedef typename traits::derived_of<L>::type derived_; \
+ return OP::call<policy_>(static_cast<const derived_&> (l),r); \
+ } \
+ \
+ template<typename L,typename R> \
+ typename boost::enable_if_c< \
+ traits::are_bases_of_equal_to<L,false,R,true>::value, \
+ bool \
+ >::type \
+ operator SYMB(const L& l,const R& r){ \
+ typedef typename traits::policy_of<R>::type policy_; \
+ typedef typename traits::derived_of<R>::type derived_; \
+ return OP::call<policy_>(r,static_cast<const derived_&> (r)); \
+ } \
+ \
+ template<typename L,typename R> \
+ typename boost::enable_if_c< \
+ traits::are_bases_of_equal_to<L,true,R,true>::value, \
+ bool \
+ >::type \
+ operator SYMB(const L& l,const R& r){ \
+ typedef typename traits::policy_of<L>::type policy1_; \
+ typedef typename traits::policy_of<R>::type policy2_; \
+ BOOST_MPL_ASSERT((boost::is_same<policy1_,policy2_>)); \
+ typedef typename traits::derived_of<L>::type derived1_; \
+ typedef typename traits::derived_of<R>::type derived2_; \
+ return OP::call<policy1_>( \
+ static_cast<const derived1_&> (l), \
+ static_cast<const derived2_&> (r) \
+ ); \
+ } \
+/**/
+
+BOOST_ASSIGN_DETAIL_COMPARISON_OP( == , comparison_op::forward::equal )
+//BOOST_ASSIGN_DETAIL_COMPARISON_OP( != , comparison_op::forward::not_equal )
+//BOOST_ASSIGN_DETAIL_COMPARISON_OP( < , comparison_op::forward::less )
+//BOOST_ASSIGN_DETAIL_COMPARISON_OP( > , comparison_op::forward::greater )
+//BOOST_ASSIGN_DETAIL_COMPARISON_OP( <= , comparison_op::forward::less_or_equal )
+//BOOST_ASSIGN_DETAIL_COMPARISON_OP( >= , comparison_op::forward::greater_or_equal )
+
+}// comparison_op
+}// detail
+}// assign
+}// boost
+
+#endif

Added: sandbox/statistics/detail/assign/boost/assign/auto_size/comparison_op/range.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/comparison_op/range.hpp 2010-03-16 19:13:47 EDT (Tue, 16 Mar 2010)
@@ -0,0 +1,57 @@
+
+
+//////////////////////////////////////////////////////////////////////////////
+// assign::detail::comparison_op::range.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_COMPARISON_OP_RANGE_ER_2010_HPP
+#define BOOST_ASSIGN_DETAIL_COMPARISON_OP_RANGE_ER_2010_HPP
+#include <boost/assign/auto_size/comparison_op/crtp.hpp>
+#include <boost/assign/auto_size/comparison_op/completed_policy.hpp>
+
+namespace boost{
+namespace assign{
+namespace detail{
+namespace range_comparison_op{
+
+ // Let D1, D2 and R model Range, and for D in {D1,D2}, D derives from
+ // base_of<D>::type
+ // then defines for Op in {==,!=,<,>,<=,>=},
+ // Op(D1&,D2&)
+ // Op(D1&,R&)
+ // Op(R, D2&)
+ // etc.
+ struct fundamental_policy{
+
+ template<typename L,typename R>
+ static bool equal(const L& l,const R& r){
+ return ::boost::iterator_range_detail::equal( l, r );
+ }
+ template<typename L,typename R>
+ static bool less(const L& l,const R& r){
+ return ::boost::iterator_range_detail::less_than( l, r );
+ }
+
+ };
+
+ template<typename D>
+ struct base_of{
+ typedef comparison_op::crtp<
+ D,
+ comparison_op::completed_policy<
+ range_comparison_op::fundamental_policy
+ >
+ > type;
+ };
+
+}// range_comparison_op
+}// 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