Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58455 - in sandbox/numeric_bindings/boost/numeric/bindings: . detail
From: rutger_at_[hidden]
Date: 2009-12-18 09:21:50


Author: rutger
Date: 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
New Revision: 58455
URL: http://svn.boost.org/trac/boost/changeset/58455

Log:
Sync of work on numeric_bindings traits functions

Added:
   sandbox/numeric_bindings/boost/numeric/bindings/detail/generate_functions.hpp
      - copied, changed from r58446, /sandbox/numeric_bindings/boost/numeric/bindings/detail/generate_iter_funcs.hpp
Removed:
   sandbox/numeric_bindings/boost/numeric/bindings/detail/generate_iter_funcs.hpp
Text files modified:
   sandbox/numeric_bindings/boost/numeric/bindings/begin.hpp | 62 ++++++++-----------
   sandbox/numeric_bindings/boost/numeric/bindings/detail/generate_functions.hpp | 9 +-
   sandbox/numeric_bindings/boost/numeric/bindings/end.hpp | 55 +++++++----------
   sandbox/numeric_bindings/boost/numeric/bindings/io.hpp | 2
   sandbox/numeric_bindings/boost/numeric/bindings/min_rank.hpp | 4
   sandbox/numeric_bindings/boost/numeric/bindings/noop.hpp | 4
   sandbox/numeric_bindings/boost/numeric/bindings/num_columns.hpp | 4
   sandbox/numeric_bindings/boost/numeric/bindings/num_rows.hpp | 4
   sandbox/numeric_bindings/boost/numeric/bindings/row.hpp | 15 ++--
   sandbox/numeric_bindings/boost/numeric/bindings/size.hpp | 65 +++++++++++---------
   sandbox/numeric_bindings/boost/numeric/bindings/stride.hpp | 66 ++++++++++++---------
   sandbox/numeric_bindings/boost/numeric/bindings/tag.hpp | 124 ++++++++++++++++++++++++---------------
   sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp | 2
   13 files changed, 220 insertions(+), 196 deletions(-)

Modified: sandbox/numeric_bindings/boost/numeric/bindings/begin.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/begin.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/begin.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -9,17 +9,14 @@
 #ifndef BOOST_NUMERIC_BINDINGS_BEGIN_HPP
 #define BOOST_NUMERIC_BINDINGS_BEGIN_HPP
 
+#include <boost/numeric/bindings/detail/adaptor.hpp>
+#include <boost/numeric/bindings/detail/linear_iterator.hpp>
+#include <boost/numeric/bindings/detail/generate_functions.hpp>
 #include <boost/numeric/bindings/rank.hpp>
 #include <boost/numeric/bindings/stride.hpp>
 #include <boost/numeric/bindings/value.hpp>
-#include <boost/numeric/bindings/detail/adaptor.hpp>
-#include <boost/numeric/bindings/detail/linear_iterator.hpp>
-
-#include <boost/numeric/bindings/detail/generate_iter_funcs.hpp>
-
 #include <iostream>
 
-
 namespace boost {
 namespace numeric {
 namespace bindings {
@@ -40,17 +37,17 @@
 };
 
 template< typename T, int Dimension >
-struct begin_impl<T, mpl::int_<Dimension> > {
+struct begin_impl<T, tag::index<Dimension> > {
 
- typedef mpl::int_<Dimension> dim_type;
+ typedef tag::index<Dimension> tag_type;
 
     typedef linear_iterator<
         typename value<T>::type,
- typename result_of::stride<T,Dimension>::type
+ typename result_of::stride< T, tag_type >::type
> result_type;
 
     static result_type invoke( T& t ) {
- return result_type( begin_value( t ), stride<Dimension>(t) );
+ return result_type( begin_value( t ), stride(t, tag_type() ) );
     }
 
 };
@@ -59,8 +56,10 @@
 
 namespace result_of {
 
-template< typename T, typename Tag = mpl::int_<1> >
+template< typename T, typename Tag = tag::index<1> >
 struct begin {
+ BOOST_STATIC_ASSERT( (is_tag<Tag>::value) );
+ BOOST_STATIC_ASSERT( (mpl::not_< is_tag<T> >::value) );
     typedef typename detail::begin_impl<T,Tag>::result_type type;
 };
 
@@ -70,30 +69,21 @@
 // Free Functions
 //
 
-// Overloads like begin< tag::value, etc. >
-
-template< typename Tag, typename T >
-typename result_of::begin<T,Tag>::type begin( T& t ) {
+//
+// Overloads like begin( t, tag )
+//
+template< typename T, typename Tag >
+inline typename result_of::begin<T,Tag>::type
+begin( T& t, Tag ) {
     return detail::begin_impl<T,Tag>::invoke( t );
 }
 
-template< typename Tag, typename T >
-typename result_of::begin<const T,Tag>::type begin( const T& t ) {
+template< typename T, typename Tag >
+inline typename result_of::begin<const T,Tag>::type
+begin( const T& t, Tag ) {
     return detail::begin_impl<const T,Tag>::invoke( t );
 }
 
-// Overloads like begin<1>, begin<2>, etc..
-
-template< int Dimension, typename T >
-typename result_of::begin<T, mpl::int_<Dimension> >::type begin( T& t ) {
- return detail::begin_impl< T, mpl::int_<Dimension> >( t );
-}
-
-template< int Dimension, typename T >
-typename result_of::begin<const T, mpl::int_<Dimension> >::type begin( const T& t ) {
- return detail::begin_impl< const T, mpl::int_<Dimension> >( t );
-}
-
 // Overloads for types with rank <= 1 (scalars, vectors)
 // In theory, we could provide overloads for matrices here, too,
 // if their minimal_rank is at most 1.
@@ -102,23 +92,23 @@
 typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
     typename result_of::begin< T >::type >::type
 begin( T& t ) {
- return detail::begin_impl< T, mpl::int_<1> >::invoke( t );
+ return detail::begin_impl< T, tag::index<1> >::invoke( t );
 }
 
 template< typename T >
 typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
     typename result_of::begin< const T >::type >::type
 begin( const T& t ) {
- return detail::begin_impl< const T, mpl::int_<1> >::invoke( t );
+ return detail::begin_impl< const T, tag::index<1> >::invoke( t );
 }
 
 #define GENERATE_BEGIN_INDEX( z, which, unused ) \
-GENERATE_ITER_FUNCS( begin, which, mpl::int_<which> )
+GENERATE_FUNCTIONS( begin, which, tag::index<which> )
 
-BOOST_PP_REPEAT_FROM_TO(1,2,GENERATE_BEGIN_INDEX,~)
-GENERATE_ITER_FUNCS( begin, _value, tag::value )
-GENERATE_ITER_FUNCS( begin, _row, mpl::int_<1> )
-GENERATE_ITER_FUNCS( begin, _column, mpl::int_<2> )
+BOOST_PP_REPEAT_FROM_TO(1,3,GENERATE_BEGIN_INDEX,~)
+GENERATE_FUNCTIONS( begin, _value, tag::value )
+GENERATE_FUNCTIONS( begin, _row, tag::index<1> )
+GENERATE_FUNCTIONS( begin, _column, tag::index<2> )
 
 } // namespace bindings
 } // namespace numeric

Copied: sandbox/numeric_bindings/boost/numeric/bindings/detail/generate_functions.hpp (from r58446, /sandbox/numeric_bindings/boost/numeric/bindings/detail/generate_iter_funcs.hpp)
==============================================================================
--- /sandbox/numeric_bindings/boost/numeric/bindings/detail/generate_iter_funcs.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/detail/generate_functions.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -6,18 +6,17 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#ifndef BOOST_NUMERIC_BINDINGS_DETAIL_GENERATE_ITER_FUNCS_HPP
-#define BOOST_NUMERIC_BINDINGS_DETAIL_GENERATE_ITER_FUNCS_HPP
+#ifndef BOOST_NUMERIC_BINDINGS_DETAIL_GENERATE_FUNCTIONS_HPP
+#define BOOST_NUMERIC_BINDINGS_DETAIL_GENERATE_FUNCTIONS_HPP
 
 #include <boost/preprocessor/repetition.hpp>
 #include <boost/preprocessor/cat.hpp>
 
-
 //
-// Convenience functions
+// Macro used to generate convenience functions
 //
 
-#define GENERATE_ITER_FUNCS( function_name, suffix, tag ) \
+#define GENERATE_FUNCTIONS( function_name, suffix, tag ) \
 \
 namespace result_of {\
 \

Deleted: sandbox/numeric_bindings/boost/numeric/bindings/detail/generate_iter_funcs.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/detail/generate_iter_funcs.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
+++ (empty file)
@@ -1,49 +0,0 @@
-//
-// Copyright (c) 2009 Rutger ter Borg
-//
-// Distributed under 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_NUMERIC_BINDINGS_DETAIL_GENERATE_ITER_FUNCS_HPP
-#define BOOST_NUMERIC_BINDINGS_DETAIL_GENERATE_ITER_FUNCS_HPP
-
-#include <boost/preprocessor/repetition.hpp>
-#include <boost/preprocessor/cat.hpp>
-
-
-//
-// Convenience functions
-//
-
-#define GENERATE_ITER_FUNCS( function_name, suffix, tag ) \
-\
-namespace result_of {\
-\
-template< typename T > \
-struct BOOST_PP_CAT( function_name, suffix ) { \
- typedef typename detail::\
- BOOST_PP_CAT( function_name, _impl ) \
- <T,tag>::result_type type; \
-}; \
-\
-}\
-\
-template< typename T >\
-typename result_of:: BOOST_PP_CAT( function_name, suffix )<T>::type \
-BOOST_PP_CAT( function_name, suffix )( T& t ) {\
- return detail:: \
- BOOST_PP_CAT( function_name, _impl ) \
- <T, tag >::invoke( t );\
-}\
-\
-template< typename T >\
-typename result_of:: BOOST_PP_CAT( function_name, suffix )<const T>::type \
-BOOST_PP_CAT( function_name, suffix )( const T& t ) {\
- return detail:: \
- BOOST_PP_CAT( function_name, _impl ) \
- <const T, tag >::invoke( t );\
-}
-
-#endif

Modified: sandbox/numeric_bindings/boost/numeric/bindings/end.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/end.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/end.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -30,18 +30,18 @@
 
 };
 
-template< typename T, int Dimension >
-struct end_impl<T, mpl::int_<Dimension> > {
+template< typename T, int N >
+struct end_impl< T, tag::index<N> > {
 
- typedef mpl::int_<Dimension> dim_type;
+ typedef tag::index<N> index_type;
 
     typedef linear_iterator<
         typename value<T>::type,
- typename result_of::stride<T,Dimension>::type
+ typename result_of::stride< T, index_type >::type
> result_type;
 
     static result_type invoke( T& t ) {
- return result_type( end_value( t ), stride<Dimension>(t) );
+ return result_type( end_value( t ), stride(t, index_type() ) );
     }
 
 };
@@ -50,7 +50,7 @@
 
 namespace result_of {
 
-template< typename T, typename Tag = mpl::int_<1> >
+template< typename T, typename Tag = tag::index<1> >
 struct end {
     typedef typename detail::end_impl<T,Tag>::result_type type;
 };
@@ -60,55 +60,46 @@
 // Free Functions
 //
 
-// Overloads like begin< tag::value, etc. >
-
-template< typename Tag, typename T >
-typename result_of::end<T,Tag>::type end( T& t ) {
+//
+// Overloads like end( t, tag );
+//
+template< typename T, typename Tag >
+inline typename result_of::end<T,Tag>::type
+end( T& t, Tag ) {
     return detail::end_impl<T,Tag>::invoke( t );
 }
 
-template< typename Tag, typename T >
-typename result_of::end<const T,Tag>::type end( const T& t ) {
+template< typename T, typename Tag >
+inline typename result_of::end<const T,Tag>::type
+end( const T& t, Tag ) {
     return detail::end_impl<const T,Tag>::invoke( t );
 }
 
-// Overloads like end<1>, end<2>, etc..
-
-template< int Dimension, typename T >
-typename result_of::end<T, mpl::int_<Dimension> >::type end( T& t ) {
- return detail::end_impl<T, mpl::int_<Dimension> >( t );
-}
-
-template< int Dimension, typename T >
-typename result_of::end<const T, mpl::int_<Dimension> >::type end( const T& t ) {
- return detail::end_impl<const T, mpl::int_<Dimension> >( t );
-}
-
 // Overloads for types with rank <= 1 (scalars, vectors)
 // In theory, we could provide overloads for matrices here, too,
 // if their minimal_rank is at most 1.
 
 template< typename T >
 typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
- typename result_of::end< T, mpl::int_<1> >::type >::type
+ typename result_of::end< T, tag::index<1> >::type >::type
 end( T& t ) {
- return detail::end_impl<T,mpl::int_<1> >::invoke( t );
+ return detail::end_impl<T,tag::index<1> >::invoke( t );
 }
 
 template< typename T >
 typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
     typename result_of::end< const T >::type >::type
 end( const T& t ) {
- return detail::end_impl<const T,mpl::int_<1> >::invoke( t );
+ return detail::end_impl<const T, tag::index<1> >::invoke( t );
 }
 
 #define GENERATE_END_INDEX( z, which, unused ) \
-GENERATE_ITER_FUNCS( end, which, mpl::int_<which> )
+GENERATE_FUNCTIONS( end, which, mpl::int_<which> )
 
-BOOST_PP_REPEAT_FROM_TO(1,2,GENERATE_END_INDEX,~)
-GENERATE_ITER_FUNCS( end, _value, tag::value )
-GENERATE_ITER_FUNCS( end, _row, mpl::int_<1> )
-GENERATE_ITER_FUNCS( end, _column, mpl::int_<2> )
+BOOST_PP_REPEAT_FROM_TO(1,3,GENERATE_END_INDEX,~)
+GENERATE_FUNCTIONS( end, _value, tag::value )
+GENERATE_FUNCTIONS( end, _row, mpl::int_<1> )
+GENERATE_FUNCTIONS( end, _column, mpl::int_<2> )
 
 
 } // namespace bindings

Modified: sandbox/numeric_bindings/boost/numeric/bindings/io.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/io.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/io.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -23,7 +23,7 @@
 
 template< typename Stream, typename T >
 Stream& pretty_print( Stream& os, const T& t ) {
- os << "[" << size<1>(t) << "] ";
+ os << "[" << size1(t) << "] ";
     typename result_of::begin< const T >::type i = begin(t);
     if ( i != end(t) ) {
         os << *i;

Modified: sandbox/numeric_bindings/boost/numeric/bindings/min_rank.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/min_rank.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/min_rank.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -6,8 +6,8 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#ifndef BOOST_NUMERIC_BINDINGS_MIN_TENSOR_RANK_HPP
-#define BOOST_NUMERIC_BINDINGS_MIN_TENSOR_RANK_HPP
+#ifndef BOOST_NUMERIC_BINDINGS_MIN_RANK_HPP
+#define BOOST_NUMERIC_BINDINGS_MIN_RANK_HPP
 
 #include <boost/numeric/bindings/detail/adaptor.hpp>
 

Modified: sandbox/numeric_bindings/boost/numeric/bindings/noop.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/noop.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/noop.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -34,8 +34,8 @@
     typedef adaptor< typename boost::remove_const<T>::type, T > underlying_adaptor;
     typedef typename underlying_adaptor::property_map property_map;
 
- static typename result_of::size<T,1>::type size1( const Id& id ) {
- return size<1>( id.get() );
+ static typename result_of::size1<T>::type size1( const Id& id ) {
+ return bindings::size1( id.get() );
     }
 
     static typename result_of::begin_value< T >::type begin_value( Id& id ) {

Modified: sandbox/numeric_bindings/boost/numeric/bindings/num_columns.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/num_columns.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/num_columns.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -18,14 +18,14 @@
 
 template< typename T >
 struct num_columns {
- typedef typename result_of::size<T,2>::type type;
+ typedef typename result_of::size2<T>::type type;
 };
 
 } // namespace result_of
 
 template< typename T >
 inline typename result_of::num_columns<T>::type num_columns( const T& t ) {
- return size<2>( t );
+ return size2( t );
 }
 
 } // bindings

Modified: sandbox/numeric_bindings/boost/numeric/bindings/num_rows.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/num_rows.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/num_rows.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -18,14 +18,14 @@
 
 template< typename T >
 struct num_rows {
- typedef typename result_of::size<T,1>::type type;
+ typedef typename result_of::size1<T>::type type;
 };
 
 } // namespace result_of
 
 template< typename T >
 inline typename result_of::num_rows<T>::type num_rows( const T& t ) {
- return size<1>( t );
+ return size1( t );
 }
 
 } // namespace bindings

Modified: sandbox/numeric_bindings/boost/numeric/bindings/row.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/row.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/row.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -40,25 +40,26 @@
     typedef mpl::map<
         mpl::pair< tag::value_type, value_type >,
         mpl::pair< tag::entity, tag::vector >,
- mpl::pair< tag::size_type<1>, typename result_of::size<T,2>::type >,
+ mpl::pair< tag::size_type<1>, typename result_of::size2<T>::type >,
         mpl::pair< tag::data_structure, tag::linear_array >,
- mpl::pair< tag::stride_type<1>, typename result_of::stride<T,2>::type >
+ mpl::pair< tag::stride_type<1>, typename result_of::stride2<T>::type >
> property_map;
 
- static typename result_of::size<T,2>::type size1( const Id& id ) {
- return size<2>( id.get() );
+ static typename result_of::size2<T>::type size1( const Id& id ) {
+ return bindings::size2( id.get() );
     }
 
     static typename result_of::begin_value< T >::type begin_value( Id& id ) {
- return bindings::begin_value( id.get() ) + id.m_index * stride<1>( id.get() );
+ return bindings::begin_value( id.get() ) +
+ id.m_index * bindings::stride1( id.get() );
     }
 
     static typename result_of::end_value< T >::type end_value( Id& id ) {
         return bindings::end_value( id.get() );
     }
 
- static typename result_of::stride<T,2>::type stride1( const Id& id ) {
- return stride<2>( id.get() );
+ static typename result_of::stride2<T>::type stride1( const Id& id ) {
+ return bindings::stride2( id.get() );
     }
 
 };

Modified: sandbox/numeric_bindings/boost/numeric/bindings/size.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/size.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/size.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -9,48 +9,50 @@
 #ifndef BOOST_NUMERIC_BINDINGS_SIZE_HPP
 #define BOOST_NUMERIC_BINDINGS_SIZE_HPP
 
+#include <boost/numeric/bindings/detail/generate_functions.hpp>
 #include <boost/numeric/bindings/detail/get.hpp>
 #include <boost/numeric/bindings/rank.hpp>
-#include <boost/mpl/min.hpp>
 #include <boost/mpl/and.hpp>
-#include <boost/mpl/less_equal.hpp>
+#include <boost/mpl/min.hpp>
 #include <boost/mpl/greater.hpp>
+#include <boost/mpl/less_equal.hpp>
 
 namespace boost {
 namespace numeric {
 namespace bindings {
 namespace detail {
 
-template< typename T, typename Key, typename Enable = void >
+template< typename T, typename Index, typename Enable = void >
 struct size_impl {
 
- typedef typename result_of_get< T, Key >::type result_type;
+ typedef typename tag::size_type< Index::value > key_type;
+ typedef typename result_of_get< T, key_type >::type result_type;
 
- static result_type size( const T& t ) {
- return get< Key >( t );
+ static result_type invoke( const T& t ) {
+ return get< key_type >( t );
     }
 
 };
 
-template< typename T, typename Key >
-struct size_impl< T, Key,
+template< typename T, typename Index >
+struct size_impl< T, Index,
         typename boost::enable_if< typename mpl::and_<
- mpl::greater< Key, rank<T> >,
+ mpl::greater< Index, rank<T> >,
             is_same_at< T, tag::size_type<1>, std::ptrdiff_t >
>::type >::type > {
 
     typedef std::ptrdiff_t result_type;
 
- static result_type size( const T& t ) {
- return std::min< std::ptrdiff_t >( size_impl<T, tag::size_type<1> >::size(t), 1 );
+ static result_type invoke( const T& t ) {
+ return std::min< std::ptrdiff_t >( size_impl<T, tag::index<1> >::invoke(t), 1 );
     }
 
 };
 
-template< typename T, typename Key >
-struct size_impl< T, Key,
+template< typename T, typename Index >
+struct size_impl< T, Index,
         typename boost::enable_if< typename mpl::and_<
- mpl::greater< Key, rank<T> >,
+ mpl::greater< Index, rank<T> >,
             mpl::not_< is_same_at< T, tag::size_type<1>, std::ptrdiff_t > >
>::type >::type > {
 
@@ -59,7 +61,7 @@
         mpl::int_<1>
>::type result_type;
 
- static result_type size( const T& t ) {
+ static result_type invoke( const T& t ) {
         return result_type();
     }
 
@@ -70,37 +72,40 @@
 
 namespace result_of {
 
-template< typename T, int Dimension = 1 >
+template< typename T, typename Tag = tag::index<1> >
 struct size {
- typedef typename detail::size_impl< T, tag::size_type<Dimension> >::result_type type;
+ BOOST_STATIC_ASSERT( (is_tag<Tag>::value) );
+ typedef typename detail::size_impl< T, Tag >::result_type type;
 };
 
 } // namespace result_of
 
-template< int Dimension, typename T >
-inline typename result_of::size< const T, Dimension >::type size( const T& t ) {
- return detail::size_impl< const T, tag::size_type<Dimension> >::size( t );
+//
+// Overloads for free template functions size( x, tag ),
+//
+template< typename T, typename Tag >
+inline typename result_of::size< const T, Tag >::type
+size( const T& t, Tag ) {
+ return detail::size_impl< const T, Tag >::invoke( t );
 }
 
-
-// Overloads for types with rank <= 1 (scalars, vectors)
+// Overloads for free template function size( x )
+// Valid for types with rank <= 1 (scalars, vectors)
 // In theory, we could provide overloads for matrices here, too,
 // if their minimal_rank is at most 1.
 
 template< typename T >
 typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
- typename result_of::size<T>::type >::type
-size( T& t ) {
- return detail::size_impl<T, tag::size_type<1> >::size( t );
-}
-
-template< typename T >
-typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
     typename result_of::size< const T >::type >::type
 size( const T& t ) {
- return detail::size_impl<const T, tag::size_type<1> >::size( t );
+ return detail::size_impl< const T, tag::index<1> >::invoke( t );
 }
 
+#define GENERATE_SIZE_INDEX( z, which, unused ) \
+GENERATE_FUNCTIONS( size, which, tag::index<which> )
+
+BOOST_PP_REPEAT_FROM_TO(1,3,GENERATE_SIZE_INDEX,~)
+
 } // namespace bindings
 } // namespace numeric
 } // namespace boost

Modified: sandbox/numeric_bindings/boost/numeric/bindings/stride.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/stride.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/stride.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -9,6 +9,7 @@
 #ifndef BOOST_NUMERIC_BINDINGS_STRIDE_HPP
 #define BOOST_NUMERIC_BINDINGS_STRIDE_HPP
 
+#include <boost/numeric/bindings/detail/generate_functions.hpp>
 #include <boost/numeric/bindings/detail/adaptor.hpp>
 #include <boost/numeric/bindings/detail/get.hpp>
 #include <boost/numeric/bindings/rank.hpp>
@@ -22,42 +23,43 @@
 namespace bindings {
 namespace detail {
 
-template< typename T, typename Key, typename Enable = void >
+template< typename T, typename Index, typename Enable = void >
 struct stride_impl {
 
- typedef typename result_of_get< T, Key >::type result_type;
+ typedef tag::stride_type< Index::value > key_type;
+ typedef typename result_of_get< T, key_type >::type result_type;
 
- static result_type stride( const T& t ) {
- return get< Key >( t );
+ static result_type invoke( const T& t ) {
+ return get< key_type >( t );
     }
 
 };
 
-template< typename T, typename Key >
-struct stride_impl< T, Key,
+template< typename T, typename Index >
+struct stride_impl< T, Index,
         typename boost::enable_if< typename mpl::and_<
- mpl::greater< Key, rank<T> >,
+ mpl::greater< Index, rank<T> >,
             is_same_at< T, tag::stride_type<1>, std::ptrdiff_t >
>::type >::type > {
 
     typedef std::ptrdiff_t result_type;
 
- static result_type stride( const T& t ) {
+ static result_type invoke( const T& t ) {
         return 0;
     }
 
 };
 
-template< typename T, typename Key >
-struct stride_impl< T, Key,
+template< typename T, typename Index >
+struct stride_impl< T, Index,
         typename boost::enable_if< typename mpl::and_<
- mpl::greater< Key, rank<T> >,
+ mpl::greater< Index, rank<T> >,
             mpl::not_< is_same_at< T, tag::stride_type<1>, std::ptrdiff_t > >
>::type >::type > {
 
     typedef typename mpl::int_<0> result_type;
 
- static result_type stride( const T& t ) {
+ static result_type invoke( const T& t ) {
         return result_type();
     }
 
@@ -67,37 +69,45 @@
 
 namespace result_of {
 
-template< typename T, int Dimension = 1 >
+template< typename T, typename Tag = tag::index<1> >
 struct stride {
- typedef typename detail::stride_impl< T, tag::stride_type<Dimension> >::result_type type;
+ BOOST_STATIC_ASSERT( (is_tag<Tag>::value) );
+ typedef typename detail::stride_impl< T, Tag >::result_type type;
 };
 
 } // namespace result_of
 
-template< int Dimension, typename T >
-inline typename result_of::stride< const T, Dimension >::type stride( const T& t ) {
- return detail::stride_impl< const T, tag::stride_type<Dimension> >::stride( t );
+
+//
+// Overloads for free template functions stride( x, tag ),
+//
+template< typename T, typename Tag >
+inline typename result_of::stride< const T, Tag >::type
+stride( const T& t, Tag ) {
+ return detail::stride_impl< const T, Tag >::invoke( t );
 }
 
-// Overloads for types with rank <= 1 (scalars, vectors)
+// Overloads for free template functions stride( x )
+// Valid for types with rank <= 1 (scalars, vectors)
 // In theory, we could provide overloads for matrices here, too,
 // if their minimal_rank is at most 1.
 
 template< typename T >
-typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
- typename result_of::stride<T>::type >::type
-stride( T& t ) {
- return detail::stride_impl<T, tag::stride_type<1> >::stride( t );
-}
-
-template< typename T >
-typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
- typename result_of::stride< const T >::type >::type
+inline typename
+boost::enable_if<
+ mpl::less< rank<T>, mpl::int_<2> >,
+ typename result_of::stride< const T, tag::index<1> >::type
+>::type
 stride( const T& t ) {
- return detail::stride_impl<const T, tag::stride_type<1> >::stride( t );
+ return detail::stride_impl<const T, tag::index<1> >::invoke( t );
 }
 
 
+#define GENERATE_STRIDE_INDEX( z, which, unused ) \
+GENERATE_FUNCTIONS( stride, which, tag::index<which> )
+
+BOOST_PP_REPEAT_FROM_TO(1,3,GENERATE_STRIDE_INDEX,~)
+
 } // namespace bindings
 } // namespace numeric
 } // namespace boost

Modified: sandbox/numeric_bindings/boost/numeric/bindings/tag.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/tag.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/tag.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -9,62 +9,90 @@
 #ifndef BOOST_NUMERIC_BINDINGS_TAG_HPP
 #define BOOST_NUMERIC_BINDINGS_TAG_HPP
 
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/int.hpp>
+
 namespace boost {
 namespace numeric {
 namespace bindings {
-namespace tag {
-
-// key: entity
-struct value_type {};
-struct value {};
-
-struct entity {};
-struct matrix_type {};
-struct matrix_side {};
-
-struct data_structure {};
-struct data_order {};
-struct data_side {};
-
-template< int Rank >
-struct tensor: mpl::int_< Rank > {};
-
-struct scalar: tensor<0> {};
-struct vector: tensor<1> {};
-struct matrix: tensor<2> {};
-
-template< int Dimension >
-struct size_type: mpl::int_< Dimension > {};
-
-template< int Dimension >
-struct stride_type: mpl::int_< Dimension > {};
 
-template< int Dimension >
-struct index: mpl::int_< Dimension > {};
+template< typename T >
+struct is_tag: mpl::bool_<false> {};
 
-struct contiguous: mpl::int_<1> {};
+#define ADD_TAG( tag_name ) \
+\
+namespace tag { \
+struct tag_name {}; \
+} \
+\
+template<> \
+struct is_tag< tag::tag_name >: \
+ mpl::bool_< true > {};
+
+
+#define ADD_INT_TEMPLATE_TAG( tag_name ) \
+\
+namespace tag { \
+template< int N >\
+struct tag_name: mpl::int_< N > {}; \
+} \
+template< int N > \
+struct is_tag< tag::tag_name<N> >: mpl::bool_< true > {};
+
+
+#define ADD_TAG_ALIAS( tag_name, other_tag_name ) \
+\
+namespace tag { \
+struct tag_name: other_tag_name {}; \
+} \
+\
+template<> \
+struct is_tag< tag::tag_name >: \
+ mpl::bool_< true > {};
+
+
+ADD_TAG( value_type )
+ADD_TAG( value )
+ADD_TAG( value_transform )
+
+ADD_TAG( entity )
+ADD_TAG( matrix_type )
+ADD_TAG( matrix_side )
+
+ADD_TAG( data_structure )
+ADD_TAG( data_order )
+ADD_TAG( data_side )
+
+ADD_INT_TEMPLATE_TAG( tensor )
+ADD_INT_TEMPLATE_TAG( size_type )
+ADD_INT_TEMPLATE_TAG( stride_type )
+ADD_INT_TEMPLATE_TAG( index )
 
 // Supported data structures
-struct linear_array {};
-struct triangular_array {};
-struct yale_sparse {};
-
-struct structure {};
-struct general {};
-struct triangular {};
-struct symmetric {};
-
-struct num_strides {};
-
-struct row_major {};
-struct column_major {};
-
-struct upper {};
-struct lower {};
-struct unit_upper {};
-struct unit_lower {};
+ADD_TAG( linear_array )
+ADD_TAG( triangular_array )
+ADD_TAG( yale_sparse )
+
+ADD_TAG( structure )
+ADD_TAG( general )
+ADD_TAG( triangular )
+ADD_TAG( symmetric )
+
+ADD_TAG( num_strides )
+
+ADD_TAG( row_major )
+ADD_TAG( column_major )
+
+ADD_TAG( upper )
+ADD_TAG( lower )
+ADD_TAG( unit_upper )
+ADD_TAG( unit_lower )
+
+ADD_TAG_ALIAS( scalar, tensor<0> )
+ADD_TAG_ALIAS( vector, tensor<1> )
+ADD_TAG_ALIAS( matrix, tensor<2> )
+ADD_TAG_ALIAS( contiguous, mpl::int_<1> )
 
-} // namespace tag
 } // namespace bindings
 } // namespace numeric
 } // namespace boost

Modified: sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp 2009-12-18 09:21:49 EST (Fri, 18 Dec 2009)
@@ -20,7 +20,7 @@
 namespace detail {
 
 template< typename T >
-struct trans_wrapper: reference_wrapper<T> {}
+struct trans_wrapper: reference_wrapper<T> {};
 
 template< typename T, typename Id, typename Enable >
 struct adaptor< trans_wrapper<T>, Id, Enable > {


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