blob: 7152c2d8218640b8621c7b4a70f40614ad84013a [file] [log] [blame]
Neil MacIntoshcec26a22016-02-24 11:26:28 -08001///////////////////////////////////////////////////////////////////////////////
2//
3// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
4//
5// This code is licensed under the MIT License (MIT).
6//
7// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
13// THE SOFTWARE.
14//
15///////////////////////////////////////////////////////////////////////////////
16
17#pragma once
18
19#ifndef GSL_SPAN_H
20#define GSL_SPAN_H
21
22#include "gsl_assert.h"
23#include "gsl_util.h"
Neil MacIntoshba8ebef2016-05-29 17:06:29 -070024#include "byte.h"
Neil MacIntoshcec26a22016-02-24 11:26:28 -080025#include <array>
Neil MacIntoshcec26a22016-02-24 11:26:28 -080026#include <limits>
Neil MacIntoshd3929c52016-02-24 16:11:33 -080027#include <iterator>
Neil MacIntoshcec26a22016-02-24 11:26:28 -080028#include <stdexcept>
29#include <type_traits>
30#include <utility>
31
32#ifdef _MSC_VER
33
34// turn off some warnings that are noisy about our Expects statements
35#pragma warning(push)
36#pragma warning(disable : 4127) // conditional expression is constant
37
38// No MSVC does constexpr fully yet
39#pragma push_macro("constexpr")
40#define constexpr
41
42// VS 2013 workarounds
43#if _MSC_VER <= 1800
44
45#define GSL_MSVC_HAS_VARIADIC_CTOR_BUG
46#define GSL_MSVC_NO_SUPPORT_FOR_MOVE_CTOR_DEFAULT
47
48// noexcept is not understood
49#ifndef GSL_THROW_ON_CONTRACT_VIOLATION
50#pragma push_macro("noexcept")
51#define noexcept /* nothing */
52#endif
53
54// turn off some misguided warnings
55#pragma warning(push)
56#pragma warning(disable : 4351) // warns about newly introduced aggregate initializer behavior
57#pragma warning(disable : 4512) // warns that assignment op could not be generated
58
59#endif // _MSC_VER <= 1800
60
61#endif // _MSC_VER
62
63#ifdef GSL_THROW_ON_CONTRACT_VIOLATION
64
65#ifdef _MSC_VER
66#pragma push_macro("noexcept")
67#endif
68
69#define noexcept /* nothing */
70
71#endif // GSL_THROW_ON_CONTRACT_VIOLATION
72
73namespace gsl
74{
75
Neil MacIntoshc40094a2016-03-01 12:11:41 -080076template <class ElementType, std::ptrdiff_t Extent = dynamic_extent>
77class span;
78
79
80namespace details
81{
82template <class T>
83struct is_span_oracle : std::false_type
84{
85};
86
87template <class ElementType, std::ptrdiff_t Extent>
88struct is_span_oracle<gsl::span<ElementType, Extent>> : std::true_type
89{
90};
91
92template <class T>
93struct is_span : is_span_oracle<std::remove_cv_t<T>>
94{
95};
Neil MacIntosh717a2e32016-03-16 19:39:55 -070096
97template <class From, class To>
98struct is_allowed_pointer_conversion
99 : std::integral_constant<bool,
100 std::is_pointer<From>::value &&
101 std::is_pointer<To>::value &&
102 std::is_convertible<From, To>::value
103 >
104{
105};
106
107template <class From, class To>
108struct is_allowed_integral_conversion
109 : std::integral_constant<bool,
110 std::is_integral<From>::value &&
111 std::is_integral<To>::value &&
112 sizeof(From) == sizeof(To) &&
113 alignof(From) == alignof(To) &&
114 std::is_convertible<From, To>::value
115 >
116{
117};
118
119template <class From, class To>
120struct is_allowed_element_type_conversion
121 : std::integral_constant<bool,
122 std::is_same<From, std::remove_cv_t<To>>::value ||
123 is_allowed_pointer_conversion<From, To>::value ||
124 is_allowed_integral_conversion<From, To>::value
125 >
126{
127};
128
129template <class From>
Neil MacIntoshba8ebef2016-05-29 17:06:29 -0700130struct is_allowed_element_type_conversion<From, byte>
Neil MacIntosh717a2e32016-03-16 19:39:55 -0700131 : std::integral_constant<bool, !std::is_const<From>::value>
132{
133};
134
135template <class From>
Neil MacIntoshba8ebef2016-05-29 17:06:29 -0700136struct is_allowed_element_type_conversion<From, const byte>
Neil MacIntosh717a2e32016-03-16 19:39:55 -0700137 : std::integral_constant<bool, true>
138{
139};
140
Neil MacIntoshd9d6ff02016-05-29 13:52:28 -0700141template <class Span>
142class span_iterator
143 : public std::iterator<std::random_access_iterator_tag, typename Span::element_type>
144{
145 using Base = std::iterator<std::random_access_iterator_tag, typename Span::element_type>;
146
147public:
148 using typename Base::reference;
149 using typename Base::pointer;
150 using typename Base::difference_type;
151
152 span_iterator() : span_iterator(nullptr, 0) {}
153 span_iterator(const Span* span, typename Span::index_type index) : span_(span), index_(index)
154 {
155 Expects(span == nullptr || (index_ >= 0 && index <= span_->length()));
156 }
157
158 reference operator*() const { Expects(span_); return (*span_)[index_]; }
159 pointer operator->() const { Expects(span_); return &((*span_)[index_]); }
160
161 span_iterator& operator++() noexcept
162 {
163 Expects(span_ && index_ >= 0 && index_ < span_->length());
164 ++index_;
165 return *this;
166 }
167
168 span_iterator operator++(int) noexcept
169 {
170 auto ret = *this;
171 ++(*this);
172 return ret;
173 }
174
175 span_iterator& operator--() noexcept
176 {
177 Expects(span_ && index > 0 && index_ <= span_->length());
178 --index_;
179 return *this;
180 }
181
182 span_iterator operator--(int) noexcept
183 {
184 auto ret = *this;
185 --(*this);
186 return ret;
187 }
188
189 span_iterator operator+(difference_type n) const noexcept
190 {
191 auto ret{*this};
192 return ret += n;
193 }
194
195 span_iterator& operator+=(difference_type n) noexcept
196 {
197 index_ += n;
198 Expects(span_ && index_ >= 0 && index_ <= span_->length());
199 return *this;
200 }
201
202 span_iterator operator-(difference_type n) const noexcept
203 {
204 auto ret{*this};
205 return ret -= n;
206 }
207
208 span_iterator& operator-=(difference_type n) noexcept
209 {
210 return *this += -n;
211 }
212
213 difference_type operator-(const span_iterator& rhs) const noexcept
214 {
215 Expects(span_ == rhs.span_);
216 return index_ - rhs.index_;
217 }
218
219 reference operator[](difference_type n) const noexcept
220 { return *(*this + n); }
221
222 bool operator==(const span_iterator& rhs) const noexcept
223 { return span_ == rhs.span_ && index_ == rhs.index_; }
224
225 bool operator!=(const span_iterator& rhs) const noexcept { return !(*this == rhs); }
226
227 bool operator<(const span_iterator& rhs) const noexcept
228 {
229 Expects(span_ == rhs.span_);
230 return index_ < rhs.index_;
231 }
232
233 bool operator<=(const span_iterator& rhs) const noexcept { return !(rhs < *this); }
234
235 bool operator>(const span_iterator& rhs) const noexcept { return rhs < *this; }
236
237 bool operator>=(const span_iterator& rhs) const noexcept { return !(rhs > *this); }
238
239 void swap(span_iterator& rhs) noexcept
240 {
241 std::swap(index_, rhs.index_);
242 std::swap(m_span, rhs.m_span);
243 }
244
245private:
246 const Span* span_;
247 ptrdiff_t index_;
248};
249
250template <typename Span>
251span_iterator<Span> operator+(typename span_iterator<Span>::difference_type n,
252 const span_iterator<Span>& rhs) noexcept
253{ return rhs + n; }
254
255template <typename Span>
256span_iterator<Span> operator-(typename span_iterator<Span>::difference_type n,
257 const span_iterator<Span>& rhs) noexcept
Neil MacIntosh25ff7ec2016-05-29 13:54:19 -0700258{ return rhs - n; }
Neil MacIntosh717a2e32016-03-16 19:39:55 -0700259
260
Neil MacIntoshc40094a2016-03-01 12:11:41 -0800261} // namespace details
262
263
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800264// [views.constants], constants
265constexpr const std::ptrdiff_t dynamic_extent = -1;
266
267
268// [span], class template span
Neil MacIntoshc40094a2016-03-01 12:11:41 -0800269template <class ElementType, std::ptrdiff_t Extent>
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800270class span {
271public:
272 // constants and types
273 using element_type = ElementType;
274 using index_type = std::ptrdiff_t;
275 using pointer = element_type*;
276 using reference = element_type&;
Neil MacIntoshd9d6ff02016-05-29 13:52:28 -0700277
278 using iterator = details::span_iterator<span<ElementType, Extent>>;
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800279 using reverse_iterator = std::reverse_iterator<iterator>;
Neil MacIntoshd9d6ff02016-05-29 13:52:28 -0700280
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800281 constexpr static const index_type extent = Extent;
282
283 // [span.cons], span constructors, copy, assignment, and destructor
Neil MacIntosh502cd662016-02-28 00:50:53 -0800284 constexpr span() noexcept : storage_(nullptr, extent_type<0>())
285 {}
Neil MacIntoshcc22f2b2016-02-25 11:42:26 -0800286
287 constexpr span(nullptr_t) noexcept : span()
288 {}
289
Neil MacIntosh502cd662016-02-28 00:50:53 -0800290 constexpr span(pointer ptr, index_type count) : storage_(ptr, count)
Neil MacIntosh25ff7ec2016-05-29 13:54:19 -0700291 { Expects((!ptr && count == 0) || (ptr && count >= 0)); }
Neil MacIntoshcc22f2b2016-02-25 11:42:26 -0800292
Neil MacIntosh502cd662016-02-28 00:50:53 -0800293 constexpr span(pointer firstElem, pointer lastElem)
294 : storage_(firstElem, std::distance(firstElem, lastElem))
295 {}
Neil MacIntoshcc22f2b2016-02-25 11:42:26 -0800296
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800297 template <size_t N>
Neil MacIntoshf61a9bb2016-02-29 13:16:48 -0800298 constexpr span(element_type(&arr)[N])
299 : storage_(&arr[0], extent_type<N>())
300 {}
301
302 template <size_t N>
303 constexpr span(std::array<std::remove_const_t<element_type>, N>& arr)
304 : storage_(&arr[0], extent_type<N>())
305 {}
306
Neil MacIntosh3d4c3492016-03-17 17:20:33 -0700307 template <size_t N, class = std::enable_if_t<is_const<element_type>::value>>
Neil MacIntoshf61a9bb2016-02-29 13:16:48 -0800308 constexpr span(const std::array<std::remove_const_t<element_type>, N>& arr)
309 : storage_(&arr[0], extent_type<N>())
Neil MacIntosh502cd662016-02-28 00:50:53 -0800310 {}
Neil MacIntoshcc22f2b2016-02-25 11:42:26 -0800311
Neil MacIntoshc40094a2016-03-01 12:11:41 -0800312 // NB: the SFINAE here uses .data() as a incomplete/imperfect proxy for the requirement
313 // on Container to be a contiguous sequence container.
314 template <class Container,
315 class = std::enable_if_t<!details::is_span<Container>::value &&
316 std::is_convertible<Container::pointer, pointer>::value &&
317 std::is_convertible<Container::pointer, decltype(std::declval<Container>().data())>::value>
318 >
319 constexpr span(Container& cont) : span(cont.data(), cont.size()) {}
320
Neil MacIntoshc40094a2016-03-01 12:11:41 -0800321 template <class Container,
Neil MacIntosh3d4c3492016-03-17 17:20:33 -0700322 class = std::enable_if_t<std::is_const<element_type>::value &&
323 !details::is_span<Container>::value &&
Neil MacIntoshc40094a2016-03-01 12:11:41 -0800324 std::is_convertible<Container::pointer, pointer>::value &&
325 std::is_convertible<Container::pointer, decltype(std::declval<Container>().data())>::value>
326 >
Neil MacIntosh3d4c3492016-03-17 17:20:33 -0700327 constexpr span(const Container& cont) : span(cont.data(), cont.size()) {}
328
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800329 constexpr span(const span& other) noexcept = default;
330 constexpr span(span&& other) noexcept = default;
Neil MacIntosh717a2e32016-03-16 19:39:55 -0700331
332 template <class OtherElementType, std::ptrdiff_t OtherExtent,
333 class = std::enable_if_t<!std::is_same<element_type, OtherElementType>::value &&
334 details::is_allowed_element_type_conversion<OtherElementType, element_type>::value
335 >
336 >
337 constexpr span(const span<OtherElementType, OtherExtent>& other)
338 : storage_(reinterpret_cast<pointer>(other.data()), other.length())
339 {}
340
341 template <class OtherElementType, std::ptrdiff_t OtherExtent,
342 class = std::enable_if_t<!std::is_same<element_type, OtherElementType>::value &&
343 details::is_allowed_element_type_conversion<OtherElementType, element_type>::value
344 >
345 >
346 constexpr span(span<OtherElementType, OtherExtent>&& other)
347 : storage_(reinterpret_cast<pointer>(other.data()), other.length())
Neil MacIntoshd9d6ff02016-05-29 13:52:28 -0700348 {}
Neil MacIntosh717a2e32016-03-16 19:39:55 -0700349
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800350 ~span() noexcept = default;
351 constexpr span& operator=(const span& other) noexcept = default;
352 constexpr span& operator=(span&& other) noexcept = default;
353
354 // [span.sub], span subviews
355 template <ptrdiff_t Count>
Neil MacIntoshc8a412f2016-03-18 16:49:29 -0700356 constexpr span<element_type, Count> first() const
357 {
358 Expects(Count >= 0 && Count <= size());
359 return { data(), Count };
360 }
361
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800362 template <ptrdiff_t Count>
Neil MacIntoshc8a412f2016-03-18 16:49:29 -0700363 constexpr span<element_type, Count> last() const
364 {
365 Expects(Count >= 0 && Count <= size());
366 return{ Count == 0 ? data() : data() + (size() - Count), Count };
367 }
368
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800369 template <ptrdiff_t Offset, ptrdiff_t Count = dynamic_extent>
Neil MacIntoshc8a412f2016-03-18 16:49:29 -0700370 constexpr span<element_type, Count> subspan() const
371 {
372 Expects((Offset == 0 || Offset > 0 && Offset <= size()) &&
373 (Count == dynamic_extent || Count >= 0 && Offset + Count <= size()));
374 return { data() + Offset, Count == dynamic_extent ? size() - Offset : Count };
375 }
376
377 constexpr span<element_type, dynamic_extent> first(index_type count) const
378 {
379 Expects(count >= 0 && count <= size());
380 return { data(), count };
381 }
382
383 constexpr span<element_type, dynamic_extent> last(index_type count) const
384 {
385 Expects(count >= 0 && count <= size());
386 return { count == 0 ? data() : data() + (size() - count), count };
387 }
388
389 constexpr span<element_type, dynamic_extent> subspan(index_type offset,
390 index_type count = dynamic_extent) const
391 {
392 Expects((offset == 0 || offset > 0 && offset <= size()) &&
393 (count == dynamic_extent || count >= 0 && offset + count <= size()));
394 return { data() + offset, count == dynamic_extent ? size() - offset : count };
395 }
396
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800397 // [span.obs], span observers
398 constexpr index_type length() const noexcept { return size(); }
Neil MacIntosh502cd662016-02-28 00:50:53 -0800399 constexpr index_type size() const noexcept { return storage_.size(); }
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800400 constexpr index_type length_bytes() const noexcept { return size_bytes(); }
401 constexpr index_type size_bytes() const noexcept { return size() * sizeof(element_type); }
402 constexpr bool empty() const noexcept { return size() == 0; }
403
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800404 // [span.elem], span element access
Neil MacIntoshcc22f2b2016-02-25 11:42:26 -0800405 constexpr reference operator[](index_type idx) const
406 {
Neil MacIntosh502cd662016-02-28 00:50:53 -0800407 Expects(idx >= 0 && idx < storage_.size());
408 return storage_.data()[idx];
Neil MacIntoshcc22f2b2016-02-25 11:42:26 -0800409 }
410 constexpr reference operator()(index_type idx) const { return this->operator[](idx); }
Neil MacIntosh502cd662016-02-28 00:50:53 -0800411 constexpr pointer data() const noexcept { return storage_.data(); }
Neil MacIntoshd9d6ff02016-05-29 13:52:28 -0700412
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800413 // [span.iter], span iterator support
Neil MacIntoshd9d6ff02016-05-29 13:52:28 -0700414 iterator begin() const noexcept { return {this, 0}; }
415 iterator end() const noexcept { return {this, length()}; }
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800416
Neil MacIntoshd9d6ff02016-05-29 13:52:28 -0700417 reverse_iterator rbegin() const noexcept { return {this, length()}; }
418 reverse_iterator rend() const noexcept { return {this, 0}; }
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800419
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800420private:
Neil MacIntosh502cd662016-02-28 00:50:53 -0800421 template <index_type Extent>
422 class extent_type;
423
424 template <index_type Extent>
425 class extent_type
426 {
427 public:
428 static_assert(Extent >= 0, "A fixed-size span must be >= 0 in size.");
429
430 constexpr extent_type() noexcept {}
431
432 template <index_type Other>
433 constexpr extent_type(extent_type<Other>) noexcept
434 {
435 static_assert(Other == Extent,
436 "Mismatch between fixed-size extent and size of initializing data.");
437 }
438
439 constexpr extent_type(index_type size)
440 { Expects(size == Extent); }
441
442 constexpr inline index_type size() const noexcept { return Extent; }
443 };
444
445 template <>
446 class extent_type<dynamic_extent>
447 {
448 public:
449 template <index_type Other>
450 explicit constexpr extent_type(extent_type<Other> ext) : size_(ext.size())
451 {}
452
453 explicit constexpr extent_type(index_type size) : size_(size)
454 { Expects(size >= 0); }
455
456 constexpr inline index_type size() const noexcept
457 { return size_; }
458
459 private:
460 index_type size_;
461 };
462
463 // this implementation detail class lets us take advantage of the
464 // empty base class optimization to pay for only storage of a single
465 // pointer in the case of fixed-size spans
466 template <class ExtentType>
467 class storage_type : public ExtentType
468 {
469 public:
470 template <class OtherExtentType>
471 storage_type(pointer data, OtherExtentType ext)
472 : ExtentType(ext), data_(data) {}
473
Neil MacIntosh502cd662016-02-28 00:50:53 -0800474 constexpr inline pointer data() const noexcept
475 { return data_; }
476
477 private:
478 pointer data_;
479 };
480
481 storage_type<extent_type<Extent>> storage_;
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800482};
483
484
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800485// [span.comparison], span comparison operators
486template <class ElementType, ptrdiff_t Extent>
Neil MacIntoshd63c9802016-05-29 14:05:09 -0700487constexpr bool operator==(const span<ElementType, Extent>& l, const span<ElementType, Extent>& r) noexcept
488{ return std::equal(l.begin(), l.end(), r.begin(), r.end()); }
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800489
490template <class ElementType, ptrdiff_t Extent>
Neil MacIntoshd63c9802016-05-29 14:05:09 -0700491constexpr bool operator!=(const span<ElementType, Extent>& l, const span<ElementType, Extent>& r) noexcept
492{ return !(l == r); }
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800493
494template <class ElementType, ptrdiff_t Extent>
Neil MacIntoshd63c9802016-05-29 14:05:09 -0700495constexpr bool operator<(const span<ElementType, Extent>& l, const span<ElementType, Extent>& r) noexcept
496{ return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end()); }
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800497
498template <class ElementType, ptrdiff_t Extent>
Neil MacIntoshd63c9802016-05-29 14:05:09 -0700499constexpr bool operator<=(const span<ElementType, Extent>& l, const span<ElementType, Extent>& r) noexcept
500{ return !(l > r); }
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800501
502template <class ElementType, ptrdiff_t Extent>
Neil MacIntoshd63c9802016-05-29 14:05:09 -0700503constexpr bool operator>(const span<ElementType, Extent>& l, const span<ElementType, Extent>& r) noexcept
504{ return r < l; }
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800505
506template <class ElementType, ptrdiff_t Extent>
Neil MacIntoshd63c9802016-05-29 14:05:09 -0700507constexpr bool operator>=(const span<ElementType, Extent>& l, const span<ElementType, Extent>& r) noexcept
508{ return !(l < r); }
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800509
510
Neil MacIntoshba8ebef2016-05-29 17:06:29 -0700511namespace details
512{
513 // if we only supported compilers with good constexpr support then
514 // this pair of classes could collapse down to a constexpr function
515
516 // we should use a narrow_cast<> to go to size_t, but older compilers may not see it as constexpr
517 // and so will fail compilation of the template
518 template <class ElementType, ptrdiff_t Extent>
519 struct calculate_byte_size :
520 std::integral_constant<std::ptrdiff_t, static_cast<ptrdiff_t>(sizeof(ElementType) * static_cast<size_t>(Extent))>
521 {};
522
523 template <class ElementType>
524 struct calculate_byte_size<ElementType, dynamic_extent> :
525 std::integral_constant<std::ptrdiff_t, dynamic_extent>
526 {};
527}
528
529
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800530// [span.objectrep], views of object representation
531template <class ElementType, ptrdiff_t Extent>
Neil MacIntoshba8ebef2016-05-29 17:06:29 -0700532constexpr span<const byte, details::calculate_byte_size<ElementType, Extent>::value> as_bytes(span<ElementType, Extent> s) noexcept
533{ return {reinterpret_cast<const byte*>(s.data()), s.size_bytes()}; }
Neil MacIntoshd3929c52016-02-24 16:11:33 -0800534
Neil MacIntoshba8ebef2016-05-29 17:06:29 -0700535template <class ElementType, ptrdiff_t Extent, class = std::enable_if_t<!std::is_const<ElementType>::value>>
536constexpr span<byte, details::calculate_byte_size<ElementType, Extent>::value> as_writeable_bytes(span<ElementType, Extent> s) noexcept
537{ return {reinterpret_cast<byte*>(s.data()), s.size_bytes()}; }
Neil MacIntoshcec26a22016-02-24 11:26:28 -0800538
539} // namespace gsl
540
541#ifdef _MSC_VER
542
543#undef constexpr
544#pragma pop_macro("constexpr")
545
546#if _MSC_VER <= 1800
547#pragma warning(pop)
548
549#ifndef GSL_THROW_ON_CONTRACT_VIOLATION
550#undef noexcept
551#pragma pop_macro("noexcept")
552#endif // GSL_THROW_ON_CONTRACT_VIOLATION
553
554#undef GSL_MSVC_HAS_VARIADIC_CTOR_BUG
555
556#endif // _MSC_VER <= 1800
557
558#endif // _MSC_VER
559
560#if defined(GSL_THROW_ON_CONTRACT_VIOLATION)
561
562#undef noexcept
563
564#ifdef _MSC_VER
565#pragma warning(pop)
566#pragma pop_macro("noexcept")
567#endif
568
569#endif // GSL_THROW_ON_CONTRACT_VIOLATION
570
571#endif // GSL_SPAN_H