-
Notifications
You must be signed in to change notification settings - Fork 298
/
offset.hpp
72 lines (57 loc) · 1.9 KB
/
offset.hpp
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
//
// 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_OFFSET_HPP
#define BOOST_NUMERIC_BINDINGS_DETAIL_OFFSET_HPP
#include <boost/utility/enable_if.hpp>
#include <boost/mpl/and.hpp>
#include <Core/Utils/numeric/bindings/is_column_major.hpp>
#include <Core/Utils/numeric/bindings/has_linear_array.hpp>
#include <Core/Utils/numeric/bindings/has_band_array.hpp>
#include <Core/Utils/numeric/bindings/stride.hpp>
namespace boost {
namespace numeric {
namespace bindings {
namespace detail {
template< typename T, typename Enable = void >
struct offset_impl {};
template< typename T >
struct offset_impl< T, typename boost::enable_if< has_linear_array< T > >::type > {
static std::ptrdiff_t invoke( const T& t, std::ptrdiff_t i1 ) {
return i1 * bindings::stride1( t );
}
static std::ptrdiff_t invoke( const T& t, std::ptrdiff_t i1, std::ptrdiff_t i2 ) {
return i1 * bindings::stride1( t ) +
i2 * bindings::stride2( t );
}
};
template< typename T >
struct offset_impl< T,
typename boost::enable_if<
mpl::and_<
has_band_array< T >,
is_column_major< T >
>
>::type > {
static std::ptrdiff_t invoke( const T& t, std::ptrdiff_t i1, std::ptrdiff_t i2 ) {
return i1 * bindings::stride1( t ) +
i2 * (bindings::stride2( t )-1);
}
};
template< typename T >
std::ptrdiff_t offset( const T& t, std::ptrdiff_t i1 ) {
return offset_impl< T >::invoke( t, i1 );
}
template< typename T >
std::ptrdiff_t offset( const T& t, std::ptrdiff_t i1, std::ptrdiff_t i2 ) {
return offset_impl< T >::invoke( t, i1, i2 );
}
} // namespace detail
} // namespace bindings
} // namespace numeric
} // namespace boost
#endif