Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
152 lines (134 loc) · 4.67 KB

File metadata and controls

152 lines (134 loc) · 4.67 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
140
141
142
143
144
145
146
147
148
149
150
151
152
// -*- c++ -*-
/*
* Copyright (c) 2010-2012, Jim Bosch
* All rights reserved.
*
* ndarray is distributed under a simple BSD-like license;
* see the LICENSE file that should be present in the root
* of the source distribution, or alternately available at:
* https://github.com/ndarray/ndarray
*/
#ifndef NDARRAY_ArrayTraits_h_INCLUDED
#define NDARRAY_ArrayTraits_h_INCLUDED
/**
* @file ndarray/ArrayTraits.h
*
* @brief Traits for Array.
*/
#include "ndarray_fwd.h"
#include "ndarray/ExpressionTraits.h"
#include "ndarray/detail/Core.h"
#include <boost/mpl/int.hpp>
#include <boost/mpl/bool.hpp>
namespace ndarray {
namespace detail {
template <int N, typename T2, int C2, typename T1, int C1>
struct Convertible : public boost::mpl::bool_<
(((C2>=C1 && C1>=0) || (C2<=C1 && C1<=0) || (N == 1 && C2 == -C1))
&& boost::is_convertible<T2*,T1*>::value)
> {};
} // namespace detail
/**
* @brief Dimension-specialized traits shared by Array and ArrayRef.
*
* @ingroup MainGroup
*/
template <typename T, int N, int C>
struct ArrayTraits {
typedef T Element;
typedef boost::mpl::int_<N> ND;
typedef boost::mpl::int_<C> RMC;
typedef detail::NestedIterator<T,N,C> Iterator;
typedef ArrayRef<T,N-1,(N==C)?(N-1):((C>0)?C:0)> Reference;
typedef Array<T,N-1,(N==C)?(N-1):((C>0)?C:0)> Value;
typedef detail::Core<N> Core;
typedef typename Core::ConstPtr CorePtr;
static Reference makeReference(Element * data, CorePtr const & core) {
return Reference(data, core);
}
static Iterator makeIterator(Element * data, CorePtr const & core, Offset stride) {
return Iterator(Reference(data, core), stride);
}
static void fill(Iterator iter, Iterator const & end, Element value) {
// We can't use std::fill here because NestedIterator is not formally an STL ForwardIterator;
// it has random access traversal, but it does not dereference to an addressable type (see
// http://www.boost.org/doc/libs/1_55_0/libs/iterator/doc/new-iter-concepts.html#motivation)
// Most C++ standard libraries have a fill implementation that will accept NestedIterator
// anyway, but Clang's libc++ is more strictly compliant and does not.
for (; iter != end; ++iter) {
*iter = value;
}
}
};
template <typename T>
struct ArrayTraits<T,1,0> {
typedef T Element;
typedef boost::mpl::int_<1> ND;
typedef boost::mpl::int_<0> RMC;
typedef detail::StridedIterator<Element> Iterator;
typedef Element & Reference;
typedef Element Value;
typedef detail::Core<1> Core;
typedef typename Core::ConstPtr CorePtr;
static Reference makeReference(Element * data, CorePtr const & core) {
return *data;
}
static Iterator makeIterator(Element * data, CorePtr const & core, Offset stride) {
return Iterator(data, stride);
}
static void fill(Iterator iter, Iterator const & end, Element value) {
std::fill(iter, end, value);
}
};
template <typename T>
struct ArrayTraits<T,1,1> {
typedef T Element;
typedef boost::mpl::int_<1> ND;
typedef boost::mpl::int_<1> RMC;
typedef Element * Iterator;
typedef Element & Reference;
typedef Element Value;
typedef detail::Core<1> Core;
typedef typename Core::ConstPtr CorePtr;
static Reference makeReference(Element * data, CorePtr const & core) {
return *data;
}
static Iterator makeIterator(Element * data, CorePtr const & core, Offset stride) {
return data;
}
static void fill(Iterator iter, Iterator const & end, Element value) {
std::fill(iter, end, value);
}
};
template <typename T>
struct ArrayTraits<T,1,-1> {
typedef T Element;
typedef boost::mpl::int_<1> ND;
typedef boost::mpl::int_<-1> RMC;
typedef Element * Iterator;
typedef Element & Reference;
typedef Element Value;
typedef detail::Core<1> Core;
typedef typename Core::ConstPtr CorePtr;
static Reference makeReference(Element * data, CorePtr const & core) {
return *data;
}
static Iterator makeIterator(Element * data, CorePtr const & core, Offset stride) {
return data;
}
static void fill(Iterator iter, Iterator const & end, Element value) {
std::fill(iter, end, value);
}
};
template <typename T, int N, int C>
struct ExpressionTraits< Array<T,N,C> > : public ArrayTraits<T,N,C> {
typedef Array<T,N,C> Self;
typedef boost::mpl::false_ IsScalar;
};
template <typename T, int N, int C>
struct ExpressionTraits< ArrayRef<T,N,C> > : public ArrayTraits<T,N,C> {
typedef ArrayRef<T,N,C> Self;
typedef boost::mpl::false_ IsScalar;
};
} // namespace ndarray
#endif // !NDARRAY_ArrayTraits_h_INCLUDED
Morty Proxy This is a proxified and sanitized view of the page, visit original site.