Newer
Older
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
///////////////////////////////////////////////////////////////////////////////
#pragma once
#ifndef GSL_MULTI_SPAN_H
#define GSL_MULTI_SPAN_H
#include "gsl_assert"
#include "gsl_byte"
#include "gsl_util"
#include <algorithm>
#include <array>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <iterator>
#include <limits>
#include <new>
#include <numeric>
#include <stdexcept>
#include <type_traits>
#include <utility>
#ifdef _MSC_VER
// turn off some warnings that are noisy about our Expects statements
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
// No MSVC does constexpr fully yet
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
// VS 2013 workarounds
#if _MSC_VER <= 1800
#define GSL_MSVC_HAS_VARIADIC_CTOR_BUG
#define GSL_MSVC_NO_SUPPORT_FOR_MOVE_CTOR_DEFAULT
// noexcept is not understood
#ifndef GSL_THROW_ON_CONTRACT_VIOLATION
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
#endif
// turn off some misguided warnings
#pragma warning(push)
#pragma warning(disable : 4351) // warns about newly introduced aggregate initializer behavior
#pragma warning(disable : 4512) // warns that assignment op could not be generated
#endif // _MSC_VER <= 1800
#endif // _MSC_VER
#ifdef GSL_THROW_ON_CONTRACT_VIOLATION
#ifdef _MSC_VER
#pragma push_macro("noexcept")
#endif
#define noexcept /*noexcept*/
#endif // GSL_THROW_ON_CONTRACT_VIOLATION
namespace gsl
{
/*
** begin definitions of index and bounds
*/
namespace details
{
template <typename SizeType>
struct SizeTypeTraits
{
static const SizeType max_value = std::numeric_limits<SizeType>::max();
};
template <typename... Ts>
class are_integral : public std::integral_constant<bool, true>
{
};
template <typename T, typename... Ts>
class are_integral<T, Ts...>
: public std::integral_constant<bool,
std::is_integral<T>::value && are_integral<Ts...>::value>
{
};
}
template <size_t Rank>
class index final
{
static_assert(Rank > 0, "Rank must be greater than 0!");
template <size_t OtherRank>
friend class index;
public:
static const size_t rank = Rank;
using value_type = std::ptrdiff_t;
using size_type = value_type;
using reference = std::add_lvalue_reference_t<value_type>;
using const_reference = std::add_lvalue_reference_t<std::add_const_t<value_type>>;
constexpr index() noexcept {}
constexpr index(const value_type (&values)[Rank]) noexcept
{
std::copy(values, values + Rank, elems);
}
#ifdef GSL_MSVC_HAS_VARIADIC_CTOR_BUG
template <
typename T, typename... Ts,
typename = std::enable_if_t<((sizeof...(Ts) + 1) == Rank) && std::is_integral<T>::value &&
details::are_integral<Ts...>::value>>
constexpr index(T t, Ts... ds)
: index({narrow_cast<value_type>(t), narrow_cast<value_type>(ds)...})
{
}
#else
template <typename... Ts, typename = std::enable_if_t<(sizeof...(Ts) == Rank) &&
details::are_integral<Ts...>::value>>
constexpr index(Ts... ds) noexcept : elems{narrow_cast<value_type>(ds)...}
{
}
#endif
constexpr index(const index& other) noexcept = default;
constexpr index& operator=(const index& rhs) noexcept = default;
// Preconditions: component_idx < rank
constexpr reference operator[](size_t component_idx)
{
Expects(component_idx < Rank); // Component index must be less than rank
return elems[component_idx];
}
// Preconditions: component_idx < rank
constexpr const_reference operator[](size_t component_idx) const noexcept
{
Expects(component_idx < Rank); // Component index must be less than rank
return elems[component_idx];
}
constexpr bool operator==(const index& rhs) const noexcept
{
return std::equal(elems, elems + rank, rhs.elems);
}
constexpr bool operator!=(const index& rhs) const noexcept { return !(this == rhs); }
constexpr index operator+() const noexcept { return *this; }
constexpr index operator-() const noexcept
{
index ret = *this;
std::transform(ret, ret + rank, ret, std::negate<value_type>{});
return ret;
}
constexpr index operator+(const index& rhs) const noexcept
{
index ret = *this;
ret += rhs;
return ret;
}
constexpr index operator-(const index& rhs) const noexcept
{
index ret = *this;
ret -= rhs;
return ret;
}
constexpr index& operator+=(const index& rhs) noexcept
{
std::transform(elems, elems + rank, rhs.elems, elems, std::plus<value_type>{});
return *this;
}
constexpr index& operator-=(const index& rhs) noexcept
Loading full blame...