Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60759 - in sandbox/statistics/detail/assign/boost/assign/auto_size: range traits
From: erwann.rogard_at_[hidden]
Date: 2010-03-22 00:03:28


Author: e_r
Date: 2010-03-22 00:03:27 EDT (Mon, 22 Mar 2010)
New Revision: 60759
URL: http://svn.boost.org/trac/boost/changeset/60759

Log:
m
Added:
   sandbox/statistics/detail/assign/boost/assign/auto_size/range/
   sandbox/statistics/detail/assign/boost/assign/auto_size/range/chain_l.hpp (contents, props changed)
   sandbox/statistics/detail/assign/boost/assign/auto_size/range/convert_range.hpp (contents, props changed)
   sandbox/statistics/detail/assign/boost/assign/auto_size/traits/
   sandbox/statistics/detail/assign/boost/assign/auto_size/traits/conversion_traits.hpp (contents, props changed)
   sandbox/statistics/detail/assign/boost/assign/auto_size/traits/inner_value_traits.hpp (contents, props changed)
   sandbox/statistics/detail/assign/boost/assign/auto_size/traits/reference_traits.hpp (contents, props changed)

Added: sandbox/statistics/detail/assign/boost/assign/auto_size/range/chain_l.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/range/chain_l.hpp 2010-03-22 00:03:27 EDT (Mon, 22 Mar 2010)
@@ -0,0 +1,114 @@
+//////////////////////////////////////////////////////////////////////////////
+// assign::detail::range::chain_l.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_RANGE_CHAIN_L_ER_2010_HPP
+#define BOOST_ASSIGN_DETAIL_RANGE_CHAIN_L_ER_2010_HPP
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/equal_to.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/void.hpp>
+#include <boost/range.hpp>
+#include <boost/range/chain.hpp>
+
+// This is based on
+// http://gist.github.com/287791
+// developed by MPG, but allows lvalues.
+
+namespace boost{
+namespace assign{
+namespace detail{
+namespace range{
+
+namespace result_of{
+ template<typename R1,typename R2>
+ struct chain_l{
+ static R1 r1;
+ static R2 r2;
+ typedef BOOST_TYPEOF_TPL( boost::chain(r1,r2) ) type;
+ };
+}
+
+ template<typename E,typename R1,int N>
+ class expr;
+
+ template<typename E,typename R2>
+ struct next_expr{
+ typedef expr<E,R2,E::static_size+1> type;
+ };
+
+ template<typename E,typename R1,int N>
+ struct super_of_expr : result_of::chain_l<E,R1>{};
+
+ template<typename E,typename R1>
+ struct super_of_expr<E,R1,1>{
+ typedef boost::sub_range<R1> type;
+ };
+
+ template<typename E,typename R1,int N>
+ class expr : public super_of_expr<E,R1,N>::type{
+ typedef boost::mpl::int_<1> int_1_;
+ typedef boost::mpl::int_<N> int_n_;
+ typedef typename boost::mpl::equal_to<int_1_,int_n_>::type is_first_;
+ typedef typename boost::mpl::if_<is_first_,E,E&>::type previous_;
+
+ typedef expr<E,R1,N> this_;
+
+ public:
+
+ template<typename R2>
+ struct result_impl : next_expr<this_,R2>{};
+
+ BOOST_STATIC_CONSTANT(int,static_size = N);
+
+ typedef typename super_of_expr<E,R1,N>::type super_;
+
+ explicit expr(super_ s):super_(s){}
+ explicit expr(E& p,super_ s):previous(p),super_(s){}
+
+ template<typename R2>
+ typename result_impl<R2>::type
+ operator()(R2& r2){
+ typedef typename result_impl<R2>::type res_;
+ typedef typename res_::super_ super_;
+ return res_(
+ *this,
+ super_(
+ boost::chain(*this,r2)
+ )
+ );
+ }
+
+ mutable previous_ previous;
+ };
+
+ typedef boost::mpl::void_ top_;
+
+ template<typename R1>
+ struct first_expr{
+ typedef expr<top_,R1,1> type;
+ typedef typename type::super_ super_;
+ static type call(R1& r1){
+ return type(super_(r1));
+ }
+ };
+
+
+}// range
+}// detail
+
+ template<typename R1>
+ typename detail::range::first_expr<R1>::type
+ chain_l(R1& r1){
+ typedef detail::range::first_expr<R1> caller_;
+ return caller_::call(r1);
+ }
+
+}// assign
+}// boost
+
+#endif
\ No newline at end of file

Added: sandbox/statistics/detail/assign/boost/assign/auto_size/range/convert_range.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/range/convert_range.hpp 2010-03-22 00:03:27 EDT (Mon, 22 Mar 2010)
@@ -0,0 +1,138 @@
+//////////////////////////////////////////////////////////////////////////////
+// assign::detail::range::convert.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_RANGE_CONVERT_ER_2010_HPP
+#define BOOST_ASSIGN_DETAIL_RANGE_CONVERT_ER_2010_HPP
+#include <boost/mpl/assert.hpp>
+#include <boost/range.hpp>
+#include <boost/range/adaptor/transformed.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_convertible.hpp>
+#include <boost/assign/auto_size/conversion/iterator.hpp>
+#include <boost/assign/auto_size/traits/reference_traits.hpp>
+
+// Usage:
+// convert_range<T>(r)
+// changes U = range_reference<R>::type to T.
+// convert_range(r)
+// changes U to reference_traits::convert_to<U>::type
+
+namespace boost{
+namespace assign{
+namespace detail{
+namespace adaptor{
+
+struct use_default;
+
+template<typename T = use_default>
+struct convert_range{ convert_range(){} };
+
+}// adaptor
+
+namespace result_of{
+
+ template<
+ typename Rng,
+ typename T = typename reference_traits::convert_to<
+ typename boost::range_reference<Rng>::type
+ >::type
+ >
+ struct convert_range
+ {
+ typedef adaptor::convert_range<T> adaptor_;
+ typedef typename boost::range_iterator<Rng>::type base_it_;
+ typedef detail::iterator_converter<base_it_,T> new_it_;
+ typedef boost::iterator_range<new_it_> type;
+
+ static void internal_check(){
+ typedef typename boost::range_reference<Rng>::type u_;
+ BOOST_MPL_ASSERT((boost::is_convertible<u_,T>));
+ typedef typename boost::range_reference<type>::type new_ref_;
+ BOOST_MPL_ASSERT((boost::is_same<new_ref_,T>));
+ }
+ static type call(Rng& r){
+ internal_check();
+ return type(
+ detail::convert_iterator<T>(boost::begin(r)),
+ detail::convert_iterator<T>(boost::end(r))
+ );
+ }
+ };
+
+}
+
+ // convert_range
+
+ template<typename T,typename Rng>
+ typename detail::result_of::convert_range<Rng,T>::type
+ convert_range( Rng& r)
+ {
+ typedef detail::result_of::convert_range<Rng,T> caller_;
+ return caller_::call( r );
+ }
+
+ template<typename T,typename Rng>
+ typename detail::result_of::convert_range<const Rng,T>::type
+ convert_range( const Rng& r)
+ {
+ typedef detail::result_of::convert_range<const Rng,T> caller_;
+ return caller_::call( r );
+ }
+
+/*
+ template<typename Rng>
+ typename detail::result_of::convert_range<Rng>::type
+ convert_range( Rng& r)
+ {
+ typedef detail::result_of::convert_range<Rng> caller_;
+ return caller_::call( r );
+ }
+
+ template<typename Rng>
+ typename detail::result_of::convert_range<const Rng>::type
+ convert_range( const Rng& r)
+ {
+ typedef detail::result_of::convert_range<const Rng> caller_;
+ return caller_::call( r );
+ }
+
+ // operator|
+
+ template<typename T,typename Rng>
+ inline typename detail::result_of::convert_range<Rng,T>::type
+ operator|( Rng& r, const detail::adaptor::convert_range<T>& f )
+ {
+ return convert_range<T>(r);
+ }
+
+ template<typename T,typename Rng>
+ inline typename detail::result_of::convert_range<const Rng,T>::type
+ operator|( const Rng& r, const detail::adaptor::convert_range<T>& f )
+ {
+ return convert_range<T>(r);
+ }
+
+ template<typename Rng>
+ inline typename detail::result_of::convert_range<Rng>::type
+ operator|( Rng& r, const detail::adaptor::convert_range<>& f )
+ {
+ return convert_range(r);
+ }
+
+ template<typename Rng>
+ inline typename detail::result_of::convert_range<const Rng>::type
+ operator|( const Rng& r, const detail::adaptor::convert_range<>& f )
+ {
+ return convert_range(r);
+ }
+*/
+}// detail
+}// assign
+}// boost
+
+#endif

Added: sandbox/statistics/detail/assign/boost/assign/auto_size/traits/conversion_traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/traits/conversion_traits.hpp 2010-03-22 00:03:27 EDT (Mon, 22 Mar 2010)
@@ -0,0 +1,73 @@
+//////////////////////////////////////////////////////////////////////////////
+// assign::detail::conversion_traits.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_CONVERSION_TRAITS_ER_2010_HPP
+#define BOOST_ASSIGN_DETAIL_CONVERSION_TRAITS_ER_2010_HPP
+#include <boost/mpl/identity.hpp>
+#include <boost/type_traits/add_reference.hpp>
+#include <boost/assign/auto_size/traits/inner_value_traits.hpp>
+
+namespace boost{
+namespace assign{
+namespace detail{
+
+// A type T is mapped to a convertible type U in two steps:
+// 1) Tag = tag_of<T>::type
+// 2) U = meta::convert_to<Tag>::apply<T>::type
+// This file defines two groups:
+// Tag U
+// - itself (the default) T
+// - reference_to_inner_value inner_value<T>&
+// but the use can also define his/her own as needed.
+
+namespace conversion_traits{
+
+ namespace tag{
+ struct itself{ typedef itself type; };
+ struct reference_to_inner_value{
+ typedef reference_to_inner_value type;
+ };
+
+ // Add as needed
+ }
+
+ // Specialize as needed
+ template<typename T> struct tag_of : tag::itself{};
+
+ namespace meta{
+ template<typename T> struct identity : boost::mpl::identity<T>{};
+
+ template<typename Tag> struct convert_to{};
+
+ template<>
+ struct convert_to<conversion_traits::tag::itself>{
+ template<typename T> struct apply : identity<T>{};
+ };
+
+ template<>
+ struct convert_to<conversion_traits::tag::reference_to_inner_value>{
+ template<typename T>
+ struct apply : boost::add_reference<
+ typename detail::inner_value_traits::inner_value_of<T>::type
+ >{};
+ };
+ // Specialize further as needed
+ }// meta
+
+ template<typename T>
+ struct convert_to
+ : meta::convert_to<
+ typename conversion_traits::tag_of<T>::type
+ >::template apply<T>{};
+
+}// conversion_traits
+}// detail
+}// assign
+}// boost
+
+#endif

Added: sandbox/statistics/detail/assign/boost/assign/auto_size/traits/inner_value_traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/traits/inner_value_traits.hpp 2010-03-22 00:03:27 EDT (Mon, 22 Mar 2010)
@@ -0,0 +1,62 @@
+//////////////////////////////////////////////////////////////////////////////
+// assign::detail::inner_value_traits.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_INNER_VALUE_TRAITS_ER_2010_HPP
+#define BOOST_ASSIGN_DETAIL_INNER_VALUE_TRAITS_ER_2010_HPP
+
+namespace boost{
+namespace assign{
+namespace detail{
+namespace inner_value_traits{
+
+// A type T is mapped to a an 'inner_value', U, in two steps:
+// 1) Tag = tag_of<T>
+// 2) U = meta::inner_value<Tag>::apply<T>::type
+// This approach is useful to define a group (Tag) of types that shares the same
+// property. This file defines one group
+// Tag T U
+// nested_parameter W<V> V
+// but the use can also define his/her own as needed.
+
+ namespace tag{
+ struct nested_parameter{ typedef nested_parameter type; };
+ }// tag
+
+ // Specialize as needed
+ template<typename T> struct tag_of : tag::nested_parameter{};
+
+ namespace meta{
+ struct empty{ template<typename T> struct apply{}; };
+
+ template<typename Tag> struct inner_value_of{};
+
+ template<>
+ struct inner_value_of<
+ inner_value_traits::tag::nested_parameter
+ > : empty{};
+
+ template<>
+ template<template<typename> class W,typename T>
+ struct inner_value_of<tag::nested_parameter>
+ ::apply< W<T> >{ typedef T type; };
+
+ // Specialize further as needed
+ }// meta
+
+ template<typename T>
+ struct inner_value_of
+ : meta::inner_value_of<
+ typename inner_value_traits::tag_of<T>::type>::template apply<T>{};
+
+}// inner_value_traits
+
+}// detail
+}// assign
+}// boost
+
+#endif

Added: sandbox/statistics/detail/assign/boost/assign/auto_size/traits/reference_traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/detail/assign/boost/assign/auto_size/traits/reference_traits.hpp 2010-03-22 00:03:27 EDT (Mon, 22 Mar 2010)
@@ -0,0 +1,72 @@
+//////////////////////////////////////////////////////////////////////////////
+// assign::detail::reference_traits.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_REFERENCE_TRAITS_ER_2010_HPP
+#define BOOST_ASSIGN_DETAIL_REFERENCE_TRAITS_ER_2010_HPP
+#include <utility>
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/eval_if.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/or.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/remove_const.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+
+#include <boost/assign/auto_size/traits/conversion_traits.hpp>
+
+// Maps U = T& (or possibly U=T) to a type that is convertible to based on the
+// conversion traits.
+
+namespace boost{
+namespace assign{
+namespace detail{
+namespace reference_traits{
+
+ template<typename T>
+ struct remove_cref : boost::remove_const<
+ typename boost::remove_reference<T>::type
+ >{};
+
+ template<typename T>
+ struct is_const : boost::is_const<
+ typename boost::remove_reference<T>::type
+ >{};
+
+ template<bool use_ref,bool use_const,typename T>
+ struct filter_ref_const{
+ typedef typename reference_traits::remove_cref<T>::type value_;
+ typedef typename boost::mpl::eval_if_c<
+ use_const,
+ boost::add_const<value_>,
+ boost::mpl::identity<value_>
+ >::type const_;
+ typedef typename boost::mpl::eval_if_c<
+ use_ref,
+ boost::add_reference<const_>,
+ boost::mpl::identity<const_>
+ >::type type;
+ };
+
+ template<typename T>
+ struct convert_to{
+ typedef typename reference_traits::remove_cref<T>::type value_;
+ typedef typename conversion_traits::convert_to<value_>::type to_;
+ typedef typename boost::mpl::if_c<
+ boost::is_same<to_,value_>::value,
+ T,
+ to_
+ >::type type;
+ };
+
+}// reference_traits
+}// 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