1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
//
// 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_END_HPP
#define BOOST_NUMERIC_BINDINGS_END_HPP
#include <boost/numeric/bindings/begin.hpp>
namespace boost {
namespace numeric {
namespace bindings {
namespace detail {
template< typename T, typename Tag >
struct end_impl {};
template< typename T >
struct end_impl< T, tag::value > {
typedef typename bindings::value_type< T>::type* result_type;
static result_type invoke( T& t ) {
return adaptor_access<T>::end_value( t );
}
};
template< typename T, int N >
struct end_impl< T, tag::addressing_index<N> > {
typedef tag::addressing_index<N> tag_type;
typedef linear_iterator<
typename bindings::value_type< T>::type,
typename result_of::stride< T, tag_type >::type
> result_type;
static result_type invoke( T& t ) {
return result_type( adaptor_access<T>::end_value( t ), stride(t, tag_type() ) );
}
};
template< typename T >
struct end_impl< T, tag::index_major > {
typedef typename detail::property_at< T, tag::index_type >::type* result_type;
static result_type invoke( T& t ) {
return adaptor_access<T>::end_index_major( t );
}
};
template< typename T >
struct end_impl< T, tag::compressed_index_major > {
typedef typename detail::property_at< T, tag::index_type >::type* result_type;
static result_type invoke( T& t ) {
return adaptor_access<T>::end_compressed_index_major( t );
}
};
template< typename T >
struct end_impl< T, tag::index_minor > {
typedef typename detail::property_at< T, tag::index_type >::type* result_type;
static result_type invoke( T& t ) {
return adaptor_access<T>::end_index_minor( t );
}
};
} // namespace detail
namespace result_of {
template< typename T, typename Tag = tag::addressing_index<1> >
struct end {
BOOST_STATIC_ASSERT( (is_tag<Tag>::value) );
typedef typename detail::end_impl<T,Tag>::result_type type;
};
} // namespace result_of
//
// Free Functions
//
//
// 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 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 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, tag::addressing_index<1> >::type >::type
end( T& t ) {
return detail::end_impl<T,tag::addressing_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, tag::addressing_index<1> >::invoke( t );
}
#define GENERATE_END_INDEX( z, which, unused ) \
GENERATE_FUNCTIONS( end, which, mpl::int_<which> )
BOOST_PP_REPEAT_FROM_TO(1,3,GENERATE_END_INDEX,~)
GENERATE_FUNCTIONS( end, _value, tag::value )
GENERATE_FUNCTIONS( end, _row, tag::addressing_index<1> )
GENERATE_FUNCTIONS( end, _column, tag::addressing_index<2> )
GENERATE_FUNCTIONS( end, _index_major, tag::index_major )
GENERATE_FUNCTIONS( end, _compressed_index_major, tag::compressed_index_major )
GENERATE_FUNCTIONS( end, _index_minor, tag::index_minor )
} // namespace bindings
} // namespace numeric
} // namespace boost
#endif
|