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
|
//
// 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_GET_HPP
#define BOOST_NUMERIC_BINDINGS_DETAIL_GET_HPP
#include <boost/numeric/bindings/detail/adaptor.hpp>
#include <boost/preprocessor/repetition.hpp>
#include <boost/preprocessor/cat.hpp>
namespace boost {
namespace numeric {
namespace bindings {
namespace detail {
template< typename Key >
struct get_dispatch {};
#define GENERATE_GET( z, which, unused ) \
template<> \
struct get_dispatch< tag::size_type<which> > { \
template< typename T > \
static std::ptrdiff_t invoke( const T& t ) { \
return detail::adaptor_access<T>:: \
BOOST_PP_CAT( size, which )( t ); \
} \
};\
\
template<> \
struct get_dispatch< tag::stride_type<which> > { \
template< typename T > \
static std::ptrdiff_t invoke( const T& t ) { \
return detail::adaptor_access<T>:: \
BOOST_PP_CAT( stride, which )( t ); \
} \
};\
\
template<> \
struct get_dispatch< tag::bandwidth_type<which> > { \
template< typename T > \
static std::ptrdiff_t invoke( const T& t ) { \
return detail::adaptor_access<T>:: \
BOOST_PP_CAT( bandwidth, which )( t ); \
} \
};
BOOST_PP_REPEAT_FROM_TO(1,3,GENERATE_GET,~)
template< typename T, typename Key, typename Enable = void >
struct get_impl {};
template< typename T, typename Key >
struct get_impl< T, Key, typename boost::enable_if<
is_same_at< T, Key, std::ptrdiff_t > >::type > {
typedef std::ptrdiff_t result_type;
static std::ptrdiff_t invoke( const T& t ) {
return get_dispatch<Key>::invoke( t );
}
};
template< typename T, typename Key >
struct get_impl< T, Key, typename boost::enable_if<
mpl::not_< is_same_at< T, Key, std::ptrdiff_t > > >::type > {
typedef typename property_at< T, Key >::type result_type;
static result_type invoke( const T& ) {
return result_type();
}
};
template< typename T, typename Key >
struct result_of_get {
typedef typename get_impl< T, Key >::result_type type;
};
template< typename Key, typename T >
typename result_of_get< T, Key >::type get( const T& t ) {
return get_impl< T, Key >::invoke( t );
}
} // namespace detail
} // namespace bindings
} // namespace numeric
} // namespace boost
#endif
|