Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58610 - in sandbox/numeric_bindings/boost/numeric/bindings: . detail
From: rutger_at_[hidden]
Date: 2009-12-31 09:49:33


Author: rutger
Date: 2009-12-31 09:49:32 EST (Thu, 31 Dec 2009)
New Revision: 58610
URL: http://svn.boost.org/trac/boost/changeset/58610

Log:
updates for transpose functionality

Text files modified:
   sandbox/numeric_bindings/boost/numeric/bindings/data_order.hpp | 8 ++++++
   sandbox/numeric_bindings/boost/numeric/bindings/detail/property_map.hpp | 33 ++++++++++++++++++++++++
   sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp | 52 +++++++++++++++++++++++++++++----------
   3 files changed, 78 insertions(+), 15 deletions(-)

Modified: sandbox/numeric_bindings/boost/numeric/bindings/data_order.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/data_order.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/data_order.hpp 2009-12-31 09:49:32 EST (Thu, 31 Dec 2009)
@@ -14,12 +14,20 @@
 namespace boost {
 namespace numeric {
 namespace bindings {
+namespace result_of {
 
 template< typename T >
 struct data_order {
     typedef typename detail::property_at< T, tag::data_order >::type type;
 };
 
+} // namespace result_of
+
+template< typename T >
+typename result_of::data_order<T>::type data_order( const T& ) {
+ return result_of::data_order<T>::type();
+}
+
 } // namespace bindings
 } // namespace numeric
 } // namespace boost

Modified: sandbox/numeric_bindings/boost/numeric/bindings/detail/property_map.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/detail/property_map.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/detail/property_map.hpp 2009-12-31 09:49:32 EST (Thu, 31 Dec 2009)
@@ -9,9 +9,12 @@
 #ifndef BOOST_NUMERIC_BINDINGS_DETAIL_PROPERTY_MAP_HPP
 #define BOOST_NUMERIC_BINDINGS_DETAIL_PROPERTY_MAP_HPP
 
-#include <boost/numeric/bindings/detail/adaptor.hpp>
 #include <boost/mpl/at.hpp>
+#include <boost/mpl/fold.hpp>
 #include <boost/mpl/has_key.hpp>
+#include <boost/mpl/insert.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/numeric/bindings/detail/adaptor.hpp>
 #include <boost/type_traits/is_same.hpp>
 
 namespace boost {
@@ -27,9 +30,37 @@
     typedef typename mpl::at< typename adaptor_access<T>::property_map, Key >::type type;
 };
 
+template< typename T >
+struct property_map_of {
+ typedef typename adaptor_access<T>::property_map type;
+};
+
+
 template< typename T, typename Key, typename Value >
 struct is_same_at: is_same< typename property_at< T, Key >::type, Value > {};
 
+//
+// Meta-function to insert multiple pairs into a map by using fold. Using the
+// provided mpl::insert can (only) insert elements in a map one-by-one.
+//
+template< typename T,
+ typename P1 = mpl::na, typename P2 = mpl::na, typename P3 = mpl::na,
+ typename P4 = mpl::na, typename P5 = mpl::na, typename P6 = mpl::na,
+ typename P7 = mpl::na, typename P8 = mpl::na, typename P9 = mpl::na,
+ typename P10 = mpl::na >
+struct property_insert {
+
+ typedef mpl::vector< P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 > pair_vector;
+ typedef typename property_map_of< T >::type properties;
+
+ typedef typename mpl::fold<
+ pair_vector,
+ properties,
+ mpl::insert< mpl::_1, mpl::_2 >
+ >::type type;
+
+};
+
 } // namespace detail
 } // namespace bindings
 } // namespace numeric

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-31 09:49:32 EST (Thu, 31 Dec 2009)
@@ -6,8 +6,8 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#ifndef BOOST_NUMERIC_BINDINGS_TRANSP_HPP
-#define BOOST_NUMERIC_BINDINGS_TRANSP_HPP
+#ifndef BOOST_NUMERIC_BINDINGS_TRANS_HPP
+#define BOOST_NUMERIC_BINDINGS_TRANS_HPP
 
 #include <boost/numeric/bindings/value.hpp>
 #include <boost/numeric/bindings/size.hpp>
@@ -20,28 +20,44 @@
 namespace detail {
 
 template< typename T >
-struct trans_wrapper: reference_wrapper<T> {};
+struct trans_wrapper: reference_wrapper<T> {
+ trans_wrapper( T& t ): reference_wrapper<T>( t ) {}
+};
 
 template< typename T, typename Id, typename Enable >
 struct adaptor< trans_wrapper<T>, Id, Enable > {
 
- typedef typename value<T>::type value_type;
- typedef typename boost::mpl::max<
- boost::mpl::int_<2>,
- typename entity<T>::type >::type entity;
-
- // Flip the data order
- typedef typename flip_data_order< key_at::data_order >::type data_order;
+ typedef typename property_insert< T,
+ mpl::pair< tag::entity,
+ typename mpl::max< tag::matrix, rank< T > >::type >,
+ mpl::pair< tag::data_order,
+ typename mpl::if_< is_row_major< T >,
+ tag::column_major,
+ tag::row_major >::type >,
+ mpl::pair< tag::size_type<1>, typename result_of::size2< T >::type >,
+ mpl::pair< tag::size_type<2>, typename result_of::size1< T >::type >,
+ mpl::pair< tag::stride_type<1>, typename result_of::stride2< T >::type >,
+ mpl::pair< tag::stride_type<2>, typename result_of::stride1< T >::type >
+ >::type property_map;
 
     // Flip size1/size2
- static std::ptrdiff_t size1( const Id& t ) {
+ static typename result_of::size2< T >::type size1( const Id& t ) {
         return bindings::size2( t.get() );
     }
 
- static std::ptrdiff_t size2( const Id& t ) {
+ static typename result_of::size1< T >::type size2( const Id& t ) {
         return bindings::size1( t.get() );
     }
 
+ // Flip stride1/stride2
+ static typename result_of::stride2< T >::type stride1( const Id& t ) {
+ return bindings::stride2( t.get() );
+ }
+
+ static typename result_of::stride1< T >::type stride2( const Id& t ) {
+ return bindings::stride1( t.get() );
+ }
+
     static typename result_of::begin_value< T >::type begin_value( Id& id ) {
         return bindings::begin_value( id.get() );
     }
@@ -54,14 +70,22 @@
 
 } // namespace detail
 
+namespace result_of {
+
+template< typename T >
+struct trans {
+ typedef detail::trans_wrapper<T> type;
+};
+
+}
 
 template< typename T >
-detail::trans_wrapper<T> trans( T& underlying ) {
+typename result_of::trans<T>::type trans( T& underlying ) {
     return detail::trans_wrapper<T>( underlying );
 }
 
 template< typename T >
-detail::trans_wrapper<const T> trans( const T& underlying ) {
+typename result_of::trans<const T>::type trans( const T& underlying ) {
     return detail::trans_wrapper<const T>( underlying );
 }
 


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