GSL/include/gsl/multi_span

2294 lines
83 KiB
Plaintext
Raw Normal View History

2015-11-24 15:49:03 -05:00
///////////////////////////////////////////////////////////////////////////////
//
// 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.
//
2015-08-20 21:09:14 -04:00
///////////////////////////////////////////////////////////////////////////////
2016-02-24 14:26:28 -05:00
#ifndef GSL_MULTI_SPAN_H
#define GSL_MULTI_SPAN_H
2015-09-24 21:08:34 -04:00
#include <gsl/gsl_assert> // for Expects
#include <gsl/gsl_byte> // for byte
#include <gsl/gsl_util> // for narrow_cast
#include <algorithm> // for transform, lexicographical_compare
#include <array> // for array
2015-11-24 15:49:03 -05:00
#include <cassert>
#include <cstddef> // for ptrdiff_t, size_t, nullptr_t
#include <cstdint> // for PTRDIFF_MAX
#include <functional> // for divides, multiplies, minus, negate, plus
#include <initializer_list> // for initializer_list
#include <iterator> // for iterator, random_access_iterator_tag
#include <limits> // for numeric_limits
2015-11-12 04:23:56 -05:00
#include <new>
#include <numeric>
2015-11-12 04:23:56 -05:00
#include <stdexcept>
#include <string> // for basic_string
#include <type_traits> // for enable_if_t, remove_cv_t, is_same, is_co...
2015-08-20 21:09:14 -04:00
#include <utility>
Clang cl (#762) * Added c++17 test configurations for clang5.0 and clang6.0 * Fix #739 correct cppcorecheck warnings for clang-cl * Add clang-cl configurations * Corrections Appveyor; Temporarily disable msvc compilation for faster testing (#741) * Add path to clang-cl.exe (#741) * Escape backslash in path (#741) * Update vcpkg (#741) * Check vcpkg version; try without building vcpkg; use latest clang-cl from path (#741) * Fix blocks in ps script (#741) * Try accessing APPVEYOR_BUILD_FOLDER variable (#471) * Update span size() bug confirmation test for GCC 6.5 (#741) * MSVC flags to Clang-cl; disable c++98-compat and undefined macro warnings (#741) * Suppress clang warning on tests (missing-prototypes) (#741) * Fix clang warning -Wnewline-eof (#741) * Fix clang warning -Wdouble-promotion (#741) * Set linker explicitly * Clean condition statement * For Clang, fallback to the AppVeyor installed version of CMake * Fix clang warning -Wmissing-variable-declarations * Fallback to the MSVC linker until vcpkg has been updated * Revert "Fallback to the MSVC linker until vcpkg has been updated" This reverts commit 7263f3289e6e835c32fc7800d0c2d4e58bd21178. * Fix clang warning -Wunused-member-function * Fix clang warning -Wmissing-noreturn * Fix clang warning -Winvalid-noreturn on Windows * Add macro block end comment on large #if blocks * Workaround: fallback to mscv link.exe * Workaround: get msvc paths into PowerShell through intermediate file * Workaround: fix, remove "PATH=" from text * Workaround: try with full-path; and return user PATH * Workaround: fix, escape backslashes * Revert all since "Workaround: fallback to mscv link.exe" did not work on AppVeyor This reverts the commits: bda3d6a428e5d19e97375b2e575b0f51ff1b4bc0 97062933acfb6428535c0fdcab5d94371ce72bfc 0f4fb04bac9c2d091005b791294237250dbe0668 1b0c19afd154f4ffc5ef793014c1bc2324534fd0 a5739ea5f0cd7633527b5e5d3b16a9e3ade7149f * Suppress output of git pull; remove vcpkg from cache * Re-enable AppVeyor builds for all platforms * Correct typo Co-Authored-By: Farwaykorse <Farwaykorse@users.noreply.github.com> * Add Clang-cl 7.0.0 to the supported platforms * Revert "Fix clang warning -Wunused-member-function" This reverts commit 6fe1a4203501145ab4350b9152ecc11f3a30e49a. * Fix or locally suppress clang warning -Wunused-member-function * format touched code and correct comment * git pull --quiet * fix logic error in workaround * fix missing bracket * Suppress output of mkdir * Replace MSBuild with Ninja * Suppress output of 7z * Add architecture flags for Clang * Drop workaround for lld-link * 7-zip Overwrite and Alternative output suppression without suppressing errors Replaces 3c1c0794dd9a29908cc7c38f591bd3c7b4929677 * AppVeyor setup and CMake before build * reorder compiler configuration * remove unnecessary * remove -fno-strict-aliasing * remove -Wsign-conversion, since before v4.0 part of -Wconversion * -Wctor-dtor-privacy is GCC only * remove -Woverloaded-virtual part of -Wmost, part of -Wall * add -Wmissing-noreturn * remove the pragmas for -Wunused-member-function * Re-add MSBuild generator on AppVeyor * Print CMake commands * Add MSBuild toolset selection * Separate Architecture setting * clang-cl: add -Weverything * clang-cl -Wno-c++98-compat * clang-cl -Wno-c++98-compat-pedantic * clang-cl -Wno-missing-prototypes * clang-cl C++14 -Wno-unused-member-function * clang-cl -Wundef __GNUC__ * clang++: add -Weverything * clang++ -Wno-c++98-compat * clang++ -Wno-c++98-compat-pedantic * clang++ -Wno-missing-prototypes * clang++ -Wno-weak-vtables * clang++ C++14 -Wno-unused-member-function * clang++ fix -Wundef _MSC_VER * clang++ -Wno-padded * clang++ solve -Wdeprecated * Add AppleClang compiler target Since CMake v3.0 use of Clang for both is deprecated * clang++ v5.0 C++17 -Wno-undefined-func-template * Add VS2015 + LLVM/clang-cl to AppVeyor * Do not disable constexpr when compiling with clang-cl on Windows * Clean-up clang-only warnings (now under -Weverything) * Revert "Fix clang warning -Winvalid-noreturn on Windows" This reverts commit 2238c4760e86feebb2a18620b77312bd01055f61. * Suppress -Winvalid-noreturn for the MS STL noexception workaround * CMake: put preprocessor definition in target_compile_definitions * Solve compiler warning C4668: __GNUC__ not defined
2019-01-15 13:27:34 -05:00
#if defined(_MSC_VER) && !defined(__clang__)
2017-07-14 07:40:27 -04:00
// turn off some warnings that are noisy about our Expects statements
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4702) // unreachable code
// Turn MSVC /analyze rules that generate too much noise. TODO: fix in the tool.
#pragma warning(disable : 26495) // uninitalized member when constructor calls constructor
#pragma warning(disable : 26473) // in some instantiations we cast to the same type
#pragma warning(disable : 26490) // TODO: bug in parser - attributes and templates
#pragma warning(disable : 26465) // TODO: bug - suppression does not work on template functions
#if _MSC_VER < 1910
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
#endif // _MSC_VER < 1910
#endif // _MSC_VER
// GCC 7 does not like the signed unsigned missmatch (size_t ptrdiff_t)
// While there is a conversion from signed to unsigned, it happens at
// compiletime, so the compiler wouldn't have to warn indiscriminently, but
// could check if the source value actually doesn't fit into the target type
// and only warn in those cases.
Clang cl (#762) * Added c++17 test configurations for clang5.0 and clang6.0 * Fix #739 correct cppcorecheck warnings for clang-cl * Add clang-cl configurations * Corrections Appveyor; Temporarily disable msvc compilation for faster testing (#741) * Add path to clang-cl.exe (#741) * Escape backslash in path (#741) * Update vcpkg (#741) * Check vcpkg version; try without building vcpkg; use latest clang-cl from path (#741) * Fix blocks in ps script (#741) * Try accessing APPVEYOR_BUILD_FOLDER variable (#471) * Update span size() bug confirmation test for GCC 6.5 (#741) * MSVC flags to Clang-cl; disable c++98-compat and undefined macro warnings (#741) * Suppress clang warning on tests (missing-prototypes) (#741) * Fix clang warning -Wnewline-eof (#741) * Fix clang warning -Wdouble-promotion (#741) * Set linker explicitly * Clean condition statement * For Clang, fallback to the AppVeyor installed version of CMake * Fix clang warning -Wmissing-variable-declarations * Fallback to the MSVC linker until vcpkg has been updated * Revert "Fallback to the MSVC linker until vcpkg has been updated" This reverts commit 7263f3289e6e835c32fc7800d0c2d4e58bd21178. * Fix clang warning -Wunused-member-function * Fix clang warning -Wmissing-noreturn * Fix clang warning -Winvalid-noreturn on Windows * Add macro block end comment on large #if blocks * Workaround: fallback to mscv link.exe * Workaround: get msvc paths into PowerShell through intermediate file * Workaround: fix, remove "PATH=" from text * Workaround: try with full-path; and return user PATH * Workaround: fix, escape backslashes * Revert all since "Workaround: fallback to mscv link.exe" did not work on AppVeyor This reverts the commits: bda3d6a428e5d19e97375b2e575b0f51ff1b4bc0 97062933acfb6428535c0fdcab5d94371ce72bfc 0f4fb04bac9c2d091005b791294237250dbe0668 1b0c19afd154f4ffc5ef793014c1bc2324534fd0 a5739ea5f0cd7633527b5e5d3b16a9e3ade7149f * Suppress output of git pull; remove vcpkg from cache * Re-enable AppVeyor builds for all platforms * Correct typo Co-Authored-By: Farwaykorse <Farwaykorse@users.noreply.github.com> * Add Clang-cl 7.0.0 to the supported platforms * Revert "Fix clang warning -Wunused-member-function" This reverts commit 6fe1a4203501145ab4350b9152ecc11f3a30e49a. * Fix or locally suppress clang warning -Wunused-member-function * format touched code and correct comment * git pull --quiet * fix logic error in workaround * fix missing bracket * Suppress output of mkdir * Replace MSBuild with Ninja * Suppress output of 7z * Add architecture flags for Clang * Drop workaround for lld-link * 7-zip Overwrite and Alternative output suppression without suppressing errors Replaces 3c1c0794dd9a29908cc7c38f591bd3c7b4929677 * AppVeyor setup and CMake before build * reorder compiler configuration * remove unnecessary * remove -fno-strict-aliasing * remove -Wsign-conversion, since before v4.0 part of -Wconversion * -Wctor-dtor-privacy is GCC only * remove -Woverloaded-virtual part of -Wmost, part of -Wall * add -Wmissing-noreturn * remove the pragmas for -Wunused-member-function * Re-add MSBuild generator on AppVeyor * Print CMake commands * Add MSBuild toolset selection * Separate Architecture setting * clang-cl: add -Weverything * clang-cl -Wno-c++98-compat * clang-cl -Wno-c++98-compat-pedantic * clang-cl -Wno-missing-prototypes * clang-cl C++14 -Wno-unused-member-function * clang-cl -Wundef __GNUC__ * clang++: add -Weverything * clang++ -Wno-c++98-compat * clang++ -Wno-c++98-compat-pedantic * clang++ -Wno-missing-prototypes * clang++ -Wno-weak-vtables * clang++ C++14 -Wno-unused-member-function * clang++ fix -Wundef _MSC_VER * clang++ -Wno-padded * clang++ solve -Wdeprecated * Add AppleClang compiler target Since CMake v3.0 use of Clang for both is deprecated * clang++ v5.0 C++17 -Wno-undefined-func-template * Add VS2015 + LLVM/clang-cl to AppVeyor * Do not disable constexpr when compiling with clang-cl on Windows * Clean-up clang-only warnings (now under -Weverything) * Revert "Fix clang warning -Winvalid-noreturn on Windows" This reverts commit 2238c4760e86feebb2a18620b77312bd01055f61. * Suppress -Winvalid-noreturn for the MS STL noexception workaround * CMake: put preprocessor definition in target_compile_definitions * Solve compiler warning C4668: __GNUC__ not defined
2019-01-15 13:27:34 -05:00
#if defined(__GNUC__) && __GNUC__ > 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
2015-11-24 15:49:03 -05:00
namespace gsl
{
2015-08-20 21:09:14 -04:00
/*
** begin definitions of index and bounds
*/
namespace details
{
template <typename SizeType>
struct SizeTypeTraits
{
static const SizeType max_value = std::numeric_limits<SizeType>::max();
};
2015-10-16 20:40:57 -04:00
2015-11-24 15:49:03 -05:00
template <typename... Ts>
class are_integral : public std::integral_constant<bool, true>
{
};
2015-10-16 20:40:57 -04:00
2015-11-24 15:49:03 -05:00
template <typename T, typename... Ts>
class are_integral<T, Ts...>
: public std::integral_constant<bool,
std::is_integral<T>::value && are_integral<Ts...>::value>
{
};
} // namespace details
2015-08-20 21:09:14 -04:00
2017-02-13 15:11:45 -05:00
template <std::size_t Rank>
class multi_span_index final
2015-08-20 21:09:14 -04:00
{
static_assert(Rank > 0, "Rank must be greater than 0!");
2015-10-05 15:34:23 -04:00
2017-02-13 15:11:45 -05:00
template <std::size_t OtherRank>
friend class multi_span_index;
2015-10-05 15:34:23 -04:00
2015-08-20 21:09:14 -04:00
public:
2017-02-13 15:11:45 -05:00
static const std::size_t rank = Rank;
using value_type = std::ptrdiff_t;
2015-10-23 22:49:17 -04:00
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>>;
2015-08-20 21:09:14 -04:00
constexpr multi_span_index() noexcept {}
constexpr multi_span_index(const value_type (&values)[Rank]) noexcept
{
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
std::copy(values, values + Rank, elems);
}
2015-10-05 15:34:23 -04:00
2015-11-24 15:49:03 -05:00
template <typename... Ts, typename = std::enable_if_t<(sizeof...(Ts) == Rank) &&
details::are_integral<Ts...>::value>>
constexpr multi_span_index(Ts... ds) noexcept : elems{narrow_cast<value_type>(ds)...}
{}
2015-10-05 15:34:23 -04:00
constexpr multi_span_index(const multi_span_index& other) noexcept = default;
constexpr multi_span_index& operator=(const multi_span_index& rhs) noexcept = default;
// Preconditions: component_idx < rank
GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
2017-02-13 15:11:45 -05:00
constexpr reference operator[](std::size_t component_idx)
{
Expects(component_idx < Rank); // Component index must be less than rank
return elems[component_idx];
}
// Preconditions: component_idx < rank
GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
constexpr const_reference operator[](std::size_t component_idx) const
{
Expects(component_idx < Rank); // Component index must be less than rank
return elems[component_idx];
}
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
constexpr bool operator==(const multi_span_index& rhs) const
{
return std::equal(elems, elems + rank, rhs.elems);
}
constexpr bool operator!=(const multi_span_index& rhs) const
{
return !(*this == rhs);
}
constexpr multi_span_index operator+() const noexcept { return *this; }
constexpr multi_span_index operator-() const
{
multi_span_index ret = *this;
std::transform(ret, ret + rank, ret, std::negate<value_type>{});
return ret;
}
constexpr multi_span_index operator+(const multi_span_index& rhs) const
{
multi_span_index ret = *this;
ret += rhs;
return ret;
}
constexpr multi_span_index operator-(const multi_span_index& rhs) const
{
multi_span_index ret = *this;
ret -= rhs;
return ret;
}
constexpr multi_span_index& operator+=(const multi_span_index& rhs)
{
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
std::transform(elems, elems + rank, rhs.elems, elems,
std::plus<value_type>{});
return *this;
}
constexpr multi_span_index& operator-=(const multi_span_index& rhs)
{
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
std::transform(elems, elems + rank, rhs.elems, elems, std::minus<value_type>{});
return *this;
}
constexpr multi_span_index operator*(value_type v) const
{
multi_span_index ret = *this;
ret *= v;
return ret;
}
constexpr multi_span_index operator/(value_type v) const
{
multi_span_index ret = *this;
ret /= v;
return ret;
}
friend constexpr multi_span_index operator*(value_type v, const multi_span_index& rhs)
{
return rhs * v;
}
constexpr multi_span_index& operator*=(value_type v)
{
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
2015-11-24 15:49:03 -05:00
std::transform(elems, elems + rank, elems,
[v](value_type x) { return std::multiplies<value_type>{}(x, v); });
return *this;
}
constexpr multi_span_index& operator/=(value_type v)
{
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
GSL_SUPPRESS(bounds.3) // NO-FORMAT: attribute
2015-11-24 15:49:03 -05:00
std::transform(elems, elems + rank, elems,
[v](value_type x) { return std::divides<value_type>{}(x, v); });
return *this;
}
2015-10-05 15:34:23 -04:00
private:
value_type elems[Rank] = {};
2015-08-20 21:09:14 -04:00
};
#if !defined(_MSC_VER) || _MSC_VER >= 1910
2015-08-20 21:09:14 -04:00
struct static_bounds_dynamic_range_t
{
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
constexpr operator T() const noexcept
{
2015-11-24 15:49:03 -05:00
return narrow_cast<T>(-1);
}
};
constexpr bool operator==(static_bounds_dynamic_range_t, static_bounds_dynamic_range_t) noexcept
{
return true;
}
constexpr bool operator!=(static_bounds_dynamic_range_t, static_bounds_dynamic_range_t) noexcept
{
return false;
}
2015-08-20 21:09:14 -04:00
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
constexpr bool operator==(static_bounds_dynamic_range_t, T other) noexcept
{
return narrow_cast<T>(-1) == other;
}
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
constexpr bool operator==(T left, static_bounds_dynamic_range_t right) noexcept
2015-08-20 21:09:14 -04:00
{
return right == left;
2015-08-20 21:09:14 -04:00
}
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
constexpr bool operator!=(static_bounds_dynamic_range_t, T other) noexcept
{
return narrow_cast<T>(-1) != other;
}
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
constexpr bool operator!=(T left, static_bounds_dynamic_range_t right) noexcept
2015-08-20 21:09:14 -04:00
{
return right != left;
2015-08-20 21:09:14 -04:00
}
constexpr static_bounds_dynamic_range_t dynamic_range{};
#else
const std::ptrdiff_t dynamic_range = -1;
2015-08-20 21:09:14 -04:00
#endif
2015-11-24 15:49:03 -05:00
struct generalized_mapping_tag
{
};
struct contiguous_mapping_tag : generalized_mapping_tag
{
};
2015-08-20 21:09:14 -04:00
namespace details
{
template <std::ptrdiff_t Left, std::ptrdiff_t Right>
struct LessThan
{
static const bool value = Left < Right;
};
2015-08-20 21:09:14 -04:00
template <std::ptrdiff_t... Ranges>
2015-11-24 15:49:03 -05:00
struct BoundsRanges
{
using size_type = std::ptrdiff_t;
static const size_type Depth = 0;
static const size_type DynamicNum = 0;
static const size_type CurrentRange = 1;
static const size_type TotalSize = 1;
2015-10-23 22:49:17 -04:00
// TODO : following signature is for work around VS bug
template <typename OtherRange>
constexpr BoundsRanges(const OtherRange&, bool /* firstLevel */)
{}
2015-11-24 15:49:03 -05:00
constexpr BoundsRanges(const std::ptrdiff_t* const) {}
constexpr BoundsRanges() noexcept = default;
2015-08-20 21:09:14 -04:00
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t Dim>
constexpr void serialize(T&) const
{}
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t Dim>
constexpr size_type linearize(const T&) const
2015-11-24 15:49:03 -05:00
{
return 0;
}
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t Dim>
constexpr size_type contains(const T&) const
{
return -1;
}
constexpr size_type elementNum(std::size_t) const noexcept { return 0; }
2015-08-20 21:09:14 -04:00
constexpr size_type totalSize() const noexcept { return TotalSize; }
2015-11-24 15:49:03 -05:00
constexpr bool operator==(const BoundsRanges&) const noexcept { return true; }
};
template <std::ptrdiff_t... RestRanges>
2015-11-24 15:49:03 -05:00
struct BoundsRanges<dynamic_range, RestRanges...> : BoundsRanges<RestRanges...>
{
using Base = BoundsRanges<RestRanges...>;
using size_type = std::ptrdiff_t;
2017-02-13 15:11:45 -05:00
static const std::size_t Depth = Base::Depth + 1;
static const std::size_t DynamicNum = Base::DynamicNum + 1;
static const size_type CurrentRange = dynamic_range;
static const size_type TotalSize = dynamic_range;
private:
size_type m_bound;
2015-11-24 15:49:03 -05:00
public:
GSL_SUPPRESS(f.23) // NO-FORMAT: attribute // this pointer type is cannot be assigned nullptr - issue in not_null
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
constexpr BoundsRanges(const std::ptrdiff_t* const arr)
2015-11-24 15:49:03 -05:00
: Base(arr + 1), m_bound(*arr * this->Base::totalSize())
{
Expects(0 <= *arr);
}
constexpr BoundsRanges() noexcept : m_bound(0) {}
template <std::ptrdiff_t OtherRange, std::ptrdiff_t... RestOtherRanges>
constexpr BoundsRanges(const BoundsRanges<OtherRange, RestOtherRanges...>& other,
2015-11-24 15:49:03 -05:00
bool /* firstLevel */ = true)
: Base(static_cast<const BoundsRanges<RestOtherRanges...>&>(other), false)
, m_bound(other.totalSize())
{}
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t Dim = 0>
constexpr void serialize(T& arr) const
{
arr[Dim] = elementNum();
this->Base::template serialize<T, Dim + 1>(arr);
}
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t Dim = 0>
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
constexpr size_type linearize(const T& arr) const
2015-11-24 15:49:03 -05:00
{
const size_type index = this->Base::totalSize() * arr[Dim];
Expects(index < m_bound);
return index + this->Base::template linearize<T, Dim + 1>(arr);
}
2015-11-24 15:49:03 -05:00
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t Dim = 0>
constexpr size_type contains(const T& arr) const
{
const ptrdiff_t last = this->Base::template contains<T, Dim + 1>(arr);
2015-11-24 15:49:03 -05:00
if (last == -1) return -1;
const ptrdiff_t cur = this->Base::totalSize() * arr[Dim];
return cur < m_bound ? cur + last : -1;
}
2015-11-24 15:49:03 -05:00
GSL_SUPPRESS(c.128) // NO-FORMAT: attribute // no pointers to BoundsRanges should be ever used
constexpr size_type totalSize() const noexcept
{
return m_bound;
}
2015-11-24 15:49:03 -05:00
GSL_SUPPRESS(c.128) // NO-FORMAT: attribute // no pointers to BoundsRanges should be ever used
constexpr size_type elementNum() const noexcept
{
return totalSize() / this->Base::totalSize();
}
2015-11-24 15:49:03 -05:00
Dev/annagrin/remove explicit not null constructor (#743) * Added c++17 test configurations for clang5.0 and clang6.0 * Removed explicit not_null constructor, sloppy_not_null, added strict_not_null We added explicit not_null constructor in version 2.0.0. It proved very difficult to switch to the new version for large code bases that adopted previous versions of gsl, due to not_null used extensively in the code. Still, using explicit constructor is very benefitial for new code, since it encorages better API design and make null checks intentional. To resolve the issue, this change: - removes explicit keyword from not_null constructor - removes unneded sloppy_not_null type - adds strict_not_null type to behave the same way as v2 not_null - updates tests * Removed explicit not_null constructor, sloppy_not_null, added strict_not_null We added explicit not_null constructor in version 2.0.0. It proved very difficult to switch to the new version for large code bases that adopted previous versions of gsl, due to not_null used extensively in the code. Still, using explicit constructor is very benefitial for new code, since it encorages better API design and make null checks intentional. To resolve the issue, this change: - removes explicit keyword from not_null constructor - removes unneded sloppy_not_null type - adds strict_not_null type to behave the same way as v2 not_null - updates tests * fixed build break for gcc7 * added more tests * added more non-compiling tests * Addressed PR comments and suppressed a code analysis warning * Fixed test failure in not_null tests
2019-01-14 19:45:47 -05:00
GSL_SUPPRESS(c.128) // NO-FORMAT: attribute // no pointers to BoundsRanges should be ever used
constexpr size_type elementNum(std::size_t dim) const noexcept
{
if (dim > 0)
return this->Base::elementNum(dim - 1);
else
return elementNum();
}
constexpr bool operator==(const BoundsRanges& rhs) const noexcept
{
2015-11-24 15:49:03 -05:00
return m_bound == rhs.m_bound &&
static_cast<const Base&>(*this) == static_cast<const Base&>(rhs);
}
};
template <std::ptrdiff_t CurRange, std::ptrdiff_t... RestRanges>
2015-11-24 15:49:03 -05:00
struct BoundsRanges<CurRange, RestRanges...> : BoundsRanges<RestRanges...>
{
2015-11-24 15:49:03 -05:00
using Base = BoundsRanges<RestRanges...>;
using size_type = std::ptrdiff_t;
2017-02-13 15:11:45 -05:00
static const std::size_t Depth = Base::Depth + 1;
static const std::size_t DynamicNum = Base::DynamicNum;
static const size_type CurrentRange = CurRange;
2015-11-24 15:49:03 -05:00
static const size_type TotalSize =
Base::TotalSize == dynamic_range ? dynamic_range : CurrentRange * Base::TotalSize;
constexpr BoundsRanges(const std::ptrdiff_t* const arr) : Base(arr) {}
constexpr BoundsRanges() = default;
template <std::ptrdiff_t OtherRange, std::ptrdiff_t... RestOtherRanges>
constexpr BoundsRanges(const BoundsRanges<OtherRange, RestOtherRanges...>& other,
2015-11-24 15:49:03 -05:00
bool firstLevel = true)
: Base(static_cast<const BoundsRanges<RestOtherRanges...>&>(other), false)
{
GSL_SUPPRESS(type.4) // NO-FORMAT: attribute // TODO: false positive
2015-11-24 15:49:03 -05:00
(void) firstLevel;
}
2015-08-20 21:09:14 -04:00
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t Dim = 0>
constexpr void serialize(T& arr) const
{
arr[Dim] = elementNum();
this->Base::template serialize<T, Dim + 1>(arr);
}
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t Dim = 0>
constexpr size_type linearize(const T& arr) const
2015-11-24 15:49:03 -05:00
{
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
Expects(arr[Dim] >= 0 && arr[Dim] < CurrentRange); // Index is out of range
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
const ptrdiff_t d = arr[Dim];
return this->Base::totalSize() * d +
2015-11-24 15:49:03 -05:00
this->Base::template linearize<T, Dim + 1>(arr);
}
2015-08-20 21:09:14 -04:00
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t Dim = 0>
constexpr size_type contains(const T& arr) const
{
2015-11-24 15:49:03 -05:00
if (arr[Dim] >= CurrentRange) return -1;
const size_type last = this->Base::template contains<T, Dim + 1>(arr);
2015-11-24 15:49:03 -05:00
if (last == -1) return -1;
return this->Base::totalSize() * arr[Dim] + last;
}
GSL_SUPPRESS(c.128) // NO-FORMAT: attribute // no pointers to BoundsRanges should be ever used
constexpr size_type totalSize() const noexcept
{
return CurrentRange * this->Base::totalSize();
}
2015-08-20 21:09:14 -04:00
GSL_SUPPRESS(c.128) // NO-FORMAT: attribute // no pointers to BoundsRanges should be ever used
constexpr size_type elementNum() const noexcept
{
return CurrentRange;
}
GSL_SUPPRESS(c.128) // NO-FORMAT: attribute // no pointers to BoundsRanges should be ever used
constexpr size_type elementNum(std::size_t dim) const noexcept
{
if (dim > 0)
return this->Base::elementNum(dim - 1);
else
return elementNum();
}
constexpr bool operator==(const BoundsRanges& rhs) const noexcept
{
2015-11-24 15:49:03 -05:00
return static_cast<const Base&>(*this) == static_cast<const Base&>(rhs);
}
};
template <typename SourceType, typename TargetType>
2015-11-24 15:49:03 -05:00
struct BoundsRangeConvertible
: public std::integral_constant<bool, (SourceType::TotalSize >= TargetType::TotalSize ||
TargetType::TotalSize == dynamic_range ||
SourceType::TotalSize == dynamic_range ||
TargetType::TotalSize == 0)>
{
};
template <typename TypeChain>
struct TypeListIndexer
{
2015-11-24 15:49:03 -05:00
const TypeChain& obj_;
2019-06-06 17:16:08 -04:00
constexpr TypeListIndexer(const TypeChain& obj) : obj_(obj) {}
2015-11-24 15:49:03 -05:00
2017-02-13 15:11:45 -05:00
template <std::size_t N>
2019-06-06 17:16:08 -04:00
constexpr const TypeChain& getObj(std::true_type)
{
2015-11-24 15:49:03 -05:00
return obj_;
}
2015-11-24 15:49:03 -05:00
template <std::size_t N, typename MyChain = TypeChain,
typename MyBase = typename MyChain::Base>
2019-06-06 17:16:08 -04:00
constexpr auto getObj(std::false_type)
2015-11-24 15:49:03 -05:00
-> decltype(TypeListIndexer<MyBase>(static_cast<const MyBase&>(obj_)).template get<N>())
{
2015-11-24 15:49:03 -05:00
return TypeListIndexer<MyBase>(static_cast<const MyBase&>(obj_)).template get<N>();
}
2015-11-24 15:49:03 -05:00
2017-02-13 15:11:45 -05:00
template <std::size_t N>
2019-06-06 17:16:08 -04:00
constexpr auto get() -> decltype(getObj<N - 1>(std::integral_constant<bool, N == 0>()))
{
return getObj<N - 1>(std::integral_constant<bool, N == 0>());
}
};
template <typename TypeChain>
2019-06-06 17:16:08 -04:00
constexpr TypeListIndexer<TypeChain> createTypeListIndexer(const TypeChain& obj)
{
return TypeListIndexer<TypeChain>(obj);
}
2015-08-20 21:09:14 -04:00
2017-02-13 15:11:45 -05:00
template <std::size_t Rank, bool Enabled = (Rank > 1),
typename Ret = std::enable_if_t<Enabled, multi_span_index<Rank - 1>>>
constexpr Ret shift_left(const multi_span_index<Rank>& other) noexcept
{
Ret ret{};
for (std::size_t i = 0; i < Rank - 1; ++i)
{
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
ret[i] = other[i + 1];
}
return ret;
}
} // namespace details
2015-08-20 21:09:14 -04:00
template <typename IndexType>
class bounds_iterator;
template <std::ptrdiff_t... Ranges>
class static_bounds
{
2015-08-20 21:09:14 -04:00
public:
2015-11-24 15:49:03 -05:00
static_bounds(const details::BoundsRanges<Ranges...>&) {}
2015-08-20 21:09:14 -04:00
};
template <std::ptrdiff_t FirstRange, std::ptrdiff_t... RestRanges>
class static_bounds<FirstRange, RestRanges...>
2015-08-20 21:09:14 -04:00
{
2015-11-24 15:49:03 -05:00
using MyRanges = details::BoundsRanges<FirstRange, RestRanges...>;
2015-08-20 21:09:14 -04:00
MyRanges m_ranges;
constexpr static_bounds(const MyRanges& range) noexcept : m_ranges(range) {}
2015-11-24 15:49:03 -05:00
template <std::ptrdiff_t... OtherRanges>
friend class static_bounds;
2015-08-20 21:09:14 -04:00
public:
2017-02-13 15:11:45 -05:00
static const std::size_t rank = MyRanges::Depth;
static const std::size_t dynamic_rank = MyRanges::DynamicNum;
static const std::ptrdiff_t static_size = MyRanges::TotalSize;
2015-08-20 21:09:14 -04:00
using size_type = std::ptrdiff_t;
using index_type = multi_span_index<rank>;
using const_index_type = std::add_const_t<index_type>;
using iterator = bounds_iterator<const_index_type>;
using const_iterator = bounds_iterator<const_index_type>;
using difference_type = std::ptrdiff_t;
using sliced_type = static_bounds<RestRanges...>;
using mapping_type = contiguous_mapping_tag;
2015-08-20 21:09:14 -04:00
constexpr static_bounds() /*noexcept*/ = default;
2015-11-24 15:49:03 -05:00
2017-02-13 15:11:45 -05:00
template <typename SourceType, typename TargetType, std::size_t Rank>
2015-11-24 15:49:03 -05:00
struct BoundsRangeConvertible2;
2017-02-13 15:11:45 -05:00
template <std::size_t Rank, typename SourceType, typename TargetType,
2015-11-24 15:49:03 -05:00
typename Ret = BoundsRangeConvertible2<typename SourceType::Base,
typename TargetType::Base, Rank>>
static auto helpBoundsRangeConvertible(SourceType, TargetType, std::true_type) -> Ret;
2017-02-13 15:11:45 -05:00
template <std::size_t Rank, typename SourceType, typename TargetType>
2015-11-24 15:49:03 -05:00
static auto helpBoundsRangeConvertible(SourceType, TargetType, ...) -> std::false_type;
2017-02-13 15:11:45 -05:00
template <typename SourceType, typename TargetType, std::size_t Rank>
2015-11-24 15:49:03 -05:00
struct BoundsRangeConvertible2
: decltype(helpBoundsRangeConvertible<Rank - 1>(
SourceType(), TargetType(),
std::integral_constant<bool,
SourceType::Depth == TargetType::Depth &&
(SourceType::CurrentRange == TargetType::CurrentRange ||
TargetType::CurrentRange == dynamic_range ||
SourceType::CurrentRange == dynamic_range)>()))
{
};
template <typename SourceType, typename TargetType>
struct BoundsRangeConvertible2<SourceType, TargetType, 0> : std::true_type
{
};
template <typename SourceType, typename TargetType, std::ptrdiff_t Rank = TargetType::Depth>
struct BoundsRangeConvertible
: decltype(helpBoundsRangeConvertible<Rank - 1>(
SourceType(), TargetType(),
std::integral_constant<bool,
SourceType::Depth == TargetType::Depth &&
(!details::LessThan<SourceType::CurrentRange,
TargetType::CurrentRange>::value ||
TargetType::CurrentRange == dynamic_range ||
SourceType::CurrentRange == dynamic_range)>()))
{
};
template <typename SourceType, typename TargetType>
struct BoundsRangeConvertible<SourceType, TargetType, 0> : std::true_type
{
};
template <std::ptrdiff_t... Ranges,
typename = std::enable_if_t<details::BoundsRangeConvertible<
details::BoundsRanges<Ranges...>,
details::BoundsRanges<FirstRange, RestRanges...>>::value>>
constexpr static_bounds(const static_bounds<Ranges...>& other) : m_ranges(other.m_ranges)
2015-11-24 15:49:03 -05:00
{
Expects((MyRanges::DynamicNum == 0 && details::BoundsRanges<Ranges...>::DynamicNum == 0) ||
MyRanges::DynamicNum > 0 || other.m_ranges.totalSize() >= m_ranges.totalSize());
}
constexpr static_bounds(std::initializer_list<size_type> il) : m_ranges(il.begin())
{
// Size of the initializer list must match the rank of the array
2015-11-24 15:49:03 -05:00
Expects((MyRanges::DynamicNum == 0 && il.size() == 1 && *il.begin() == static_size) ||
MyRanges::DynamicNum == il.size());
// Size of the range must be less than the max element of the size type
2015-11-24 15:49:03 -05:00
Expects(m_ranges.totalSize() <= PTRDIFF_MAX);
}
2015-11-24 15:49:03 -05:00
constexpr sliced_type slice() const noexcept
{
2015-11-24 15:49:03 -05:00
return sliced_type{static_cast<const details::BoundsRanges<RestRanges...>&>(m_ranges)};
}
constexpr size_type stride() const noexcept { return rank > 1 ? slice().size() : 1; }
2015-11-24 15:49:03 -05:00
constexpr size_type size() const noexcept { return m_ranges.totalSize(); }
2015-11-24 15:49:03 -05:00
constexpr size_type total_size() const noexcept { return m_ranges.totalSize(); }
2015-11-24 15:49:03 -05:00
constexpr size_type linearize(const index_type& idx) const { return m_ranges.linearize(idx); }
constexpr bool contains(const index_type& idx) const noexcept
{
return m_ranges.contains(idx) != -1;
}
2015-11-24 15:49:03 -05:00
constexpr size_type operator[](std::size_t idx) const noexcept
{
return m_ranges.elementNum(idx);
}
2015-11-24 15:49:03 -05:00
2017-02-13 15:11:45 -05:00
template <std::size_t Dim = 0>
constexpr size_type extent() const noexcept
{
2015-11-24 15:49:03 -05:00
static_assert(Dim < rank,
"dimension should be less than rank (dimension count starts from 0)");
return details::createTypeListIndexer(m_ranges).template get<Dim>().elementNum();
}
2015-11-24 15:49:03 -05:00
template <typename IntType>
constexpr size_type extent(IntType dim) const
2015-11-24 15:49:03 -05:00
{
static_assert(std::is_integral<IntType>::value,
"Dimension parameter must be supplied as an integral type.");
2017-02-13 15:11:45 -05:00
auto real_dim = narrow_cast<std::size_t>(dim);
2015-11-24 15:49:03 -05:00
Expects(real_dim < rank);
return m_ranges.elementNum(real_dim);
}
constexpr index_type index_bounds() const noexcept
{
size_type extents[rank] = {};
m_ranges.serialize(extents);
2015-11-24 15:49:03 -05:00
return {extents};
}
2015-11-24 15:49:03 -05:00
template <std::ptrdiff_t... Ranges>
constexpr bool operator==(const static_bounds<Ranges...>& rhs) const noexcept
{
return this->size() == rhs.size();
}
2015-11-24 15:49:03 -05:00
template <std::ptrdiff_t... Ranges>
constexpr bool operator!=(const static_bounds<Ranges...>& rhs) const noexcept
{
return !(*this == rhs);
}
2015-11-24 15:49:03 -05:00
constexpr const_iterator begin() const noexcept
{
return const_iterator(*this, index_type{});
}
2015-11-24 15:49:03 -05:00
constexpr const_iterator end() const noexcept
{
return const_iterator(*this, this->index_bounds());
}
2015-08-20 21:09:14 -04:00
};
2017-02-13 15:11:45 -05:00
template <std::size_t Rank>
class strided_bounds {
2017-02-13 15:11:45 -05:00
template <std::size_t OtherRank>
friend class strided_bounds;
2015-08-20 21:09:14 -04:00
public:
2017-02-13 15:11:45 -05:00
static const std::size_t rank = Rank;
2015-11-24 15:49:03 -05:00
using value_type = std::ptrdiff_t;
using reference = std::add_lvalue_reference_t<value_type>;
using const_reference = std::add_const_t<reference>;
2015-11-24 15:49:03 -05:00
using size_type = value_type;
using difference_type = value_type;
using index_type = multi_span_index<rank>;
using const_index_type = std::add_const_t<index_type>;
using iterator = bounds_iterator<const_index_type>;
using const_iterator = bounds_iterator<const_index_type>;
static const value_type dynamic_rank = rank;
static const value_type static_size = dynamic_range;
using sliced_type = std::conditional_t<rank != 0, strided_bounds<rank - 1>, void>;
using mapping_type = generalized_mapping_tag;
constexpr strided_bounds(const strided_bounds&) noexcept = default;
2015-08-20 21:09:14 -04:00
constexpr strided_bounds& operator=(const strided_bounds&) noexcept = default;
2015-11-24 15:49:03 -05:00
constexpr strided_bounds(const value_type (&values)[rank], index_type strides)
2015-10-23 22:49:17 -04:00
: m_extents(values), m_strides(std::move(strides))
{}
constexpr strided_bounds(const index_type& extents, const index_type& strides) noexcept
: m_extents(extents), m_strides(strides)
{
}
constexpr index_type strides() const noexcept { return m_strides; }
2015-11-24 15:49:03 -05:00
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
constexpr size_type total_size() const noexcept
{
size_type ret = 0;
for (std::size_t i = 0; i < rank; ++i) { ret += (m_extents[i] - 1) * m_strides[i]; }
return ret + 1;
}
2015-11-24 15:49:03 -05:00
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
constexpr size_type size() const noexcept
{
size_type ret = 1;
for (std::size_t i = 0; i < rank; ++i) { ret *= m_extents[i]; }
return ret;
}
2015-11-24 15:49:03 -05:00
constexpr bool contains(const index_type& idx) const noexcept
{
for (std::size_t i = 0; i < rank; ++i)
{
2015-11-24 15:49:03 -05:00
if (idx[i] < 0 || idx[i] >= m_extents[i]) return false;
}
return true;
}
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
constexpr size_type linearize(const index_type& idx) const
{
size_type ret = 0;
for (std::size_t i = 0; i < rank; i++)
{
Expects(idx[i] < m_extents[i]); // index is out of bounds of the array
ret += idx[i] * m_strides[i];
}
return ret;
}
2015-11-24 15:49:03 -05:00
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
constexpr size_type stride() const noexcept { return m_strides[0]; }
2015-11-24 15:49:03 -05:00
template <bool Enabled = (rank > 1), typename Ret = std::enable_if_t<Enabled, sliced_type>>
constexpr sliced_type slice() const
{
2015-11-24 15:49:03 -05:00
return {details::shift_left(m_extents), details::shift_left(m_strides)};
}
2015-11-24 15:49:03 -05:00
2017-02-13 15:11:45 -05:00
template <std::size_t Dim = 0>
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
constexpr size_type extent() const noexcept
{
2015-11-24 15:49:03 -05:00
static_assert(Dim < Rank,
"dimension should be less than rank (dimension count starts from 0)");
return m_extents[Dim];
}
2015-11-24 15:49:03 -05:00
constexpr index_type index_bounds() const noexcept { return m_extents; }
2015-11-24 15:49:03 -05:00
constexpr const_iterator begin() const noexcept { return const_iterator{*this, index_type{}}; }
constexpr const_iterator end() const noexcept { return const_iterator{*this, index_bounds()}; }
private:
index_type m_extents;
index_type m_strides;
2015-08-20 21:09:14 -04:00
};
template <typename T>
2015-11-24 15:49:03 -05:00
struct is_bounds : std::integral_constant<bool, false>
{
};
template <std::ptrdiff_t... Ranges>
2015-11-24 15:49:03 -05:00
struct is_bounds<static_bounds<Ranges...>> : std::integral_constant<bool, true>
{
};
2017-02-13 15:11:45 -05:00
template <std::size_t Rank>
2015-11-24 15:49:03 -05:00
struct is_bounds<strided_bounds<Rank>> : std::integral_constant<bool, true>
{
};
2015-08-20 21:09:14 -04:00
template <typename IndexType>
class bounds_iterator
2015-08-20 21:09:14 -04:00
{
public:
2017-02-13 15:11:45 -05:00
static const std::size_t rank = IndexType::rank;
using iterator_category = std::random_access_iterator_tag;
using value_type = IndexType;
using difference_type = std::ptrdiff_t;
using pointer = value_type*;
using reference = value_type&;
using index_type = value_type;
using index_size_type = typename IndexType::value_type;
template <typename Bounds>
explicit bounds_iterator(const Bounds& bnd, value_type curr) noexcept
: boundary_(bnd.index_bounds()), curr_(std::move(curr))
{
static_assert(is_bounds<Bounds>::value, "Bounds type must be provided");
}
constexpr reference operator*() const noexcept { return curr_; }
constexpr pointer operator->() const noexcept { return &curr_; }
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute
constexpr bounds_iterator& operator++() noexcept
{
for (std::size_t i = rank; i-- > 0;)
{
if (curr_[i] < boundary_[i] - 1)
{
2015-11-30 00:34:38 -05:00
curr_[i]++;
return *this;
}
2015-11-30 00:34:38 -05:00
curr_[i] = 0;
}
// If we're here we've wrapped over - set to past-the-end.
2015-11-30 00:34:38 -05:00
curr_ = boundary_;
return *this;
}
constexpr bounds_iterator operator++(int) noexcept
{
auto ret = *this;
++(*this);
return ret;
}
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
constexpr bounds_iterator& operator--()
{
if (!less(curr_, boundary_))
{
// if at the past-the-end, set to last element
for (std::size_t i = 0; i < rank; ++i) { curr_[i] = boundary_[i] - 1; }
return *this;
}
for (std::size_t i = rank; i-- > 0;)
{
if (curr_[i] >= 1)
{
2015-11-30 00:34:38 -05:00
curr_[i]--;
return *this;
}
2015-11-30 00:34:38 -05:00
curr_[i] = boundary_[i] - 1;
}
// If we're here the preconditions were violated
// "pre: there exists s such that r == ++s"
2015-11-24 15:49:03 -05:00
Expects(false);
return *this;
}
constexpr bounds_iterator operator--(int) noexcept
{
auto ret = *this;
--(*this);
return ret;
}
constexpr bounds_iterator operator+(difference_type n) const noexcept
{
2015-11-24 15:49:03 -05:00
bounds_iterator ret{*this};
return ret += n;
}
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
constexpr bounds_iterator& operator+=(difference_type n)
{
2015-11-30 00:34:38 -05:00
auto linear_idx = linearize(curr_) + n;
std::remove_const_t<value_type> stride = 0;
stride[rank - 1] = 1;
for (std::size_t i = rank - 1; i-- > 0;) { stride[i] = stride[i + 1] * boundary_[i + 1]; }
for (std::size_t i = 0; i < rank; ++i)
{
2015-11-30 00:34:38 -05:00
curr_[i] = linear_idx / stride[i];
linear_idx = linear_idx % stride[i];
}
2015-11-24 15:49:03 -05:00
// index is out of bounds of the array
2015-11-30 00:34:38 -05:00
Expects(!less(curr_, index_type{}) && !less(boundary_, curr_));
return *this;
}
constexpr bounds_iterator operator-(difference_type n) const noexcept
{
2015-11-24 15:49:03 -05:00
bounds_iterator ret{*this};
return ret -= n;
}
constexpr bounds_iterator& operator-=(difference_type n) noexcept { return *this += -n; }
constexpr difference_type operator-(const bounds_iterator& rhs) const noexcept
{
2015-11-30 00:34:38 -05:00
return linearize(curr_) - linearize(rhs.curr_);
}
constexpr value_type operator[](difference_type n) const noexcept { return *(*this + n); }
constexpr bool operator==(const bounds_iterator& rhs) const noexcept
{
2015-11-30 00:34:38 -05:00
return curr_ == rhs.curr_;
}
constexpr bool operator!=(const bounds_iterator& rhs) const noexcept { return !(*this == rhs); }
constexpr bool operator<(const bounds_iterator& rhs) const noexcept
{
2015-11-30 00:34:38 -05:00
return less(curr_, rhs.curr_);
}
constexpr bool operator<=(const bounds_iterator& rhs) const noexcept { return !(rhs < *this); }
constexpr bool operator>(const bounds_iterator& rhs) const noexcept { return rhs < *this; }
constexpr bool operator>=(const bounds_iterator& rhs) const noexcept { return !(rhs > *this); }
void swap(bounds_iterator& rhs) noexcept
{
2015-11-30 00:34:38 -05:00
std::swap(boundary_, rhs.boundary_);
std::swap(curr_, rhs.curr_);
}
2015-11-24 15:49:03 -05:00
2015-08-20 21:09:14 -04:00
private:
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
constexpr bool less(index_type& one, index_type& other) const noexcept
{
for (std::size_t i = 0; i < rank; ++i)
{
2015-11-24 15:49:03 -05:00
if (one[i] < other[i]) return true;
}
return false;
}
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
constexpr index_size_type linearize(const value_type& idx) const noexcept
{
// TODO: Smarter impl.
// Check if past-the-end
index_size_type multiplier = 1;
index_size_type res = 0;
if (!less(idx, boundary_))
{
res = 1;
for (std::size_t i = rank; i-- > 0;)
{
res += (idx[i] - 1) * multiplier;
2015-11-30 00:34:38 -05:00
multiplier *= boundary_[i];
}
}
else
{
for (std::size_t i = rank; i-- > 0;)
{
res += idx[i] * multiplier;
2015-11-30 00:34:38 -05:00
multiplier *= boundary_[i];
}
}
return res;
}
2015-11-30 00:34:38 -05:00
value_type boundary_;
std::remove_const_t<value_type> curr_;
2015-08-20 21:09:14 -04:00
};
template <typename IndexType>
2015-11-24 15:49:03 -05:00
bounds_iterator<IndexType> operator+(typename bounds_iterator<IndexType>::difference_type n,
const bounds_iterator<IndexType>& rhs) noexcept
2015-08-20 21:09:14 -04:00
{
return rhs + n;
2015-08-20 21:09:14 -04:00
}
namespace details
{
template <typename Bounds>
constexpr std::enable_if_t<
2015-11-24 15:49:03 -05:00
std::is_same<typename Bounds::mapping_type, generalized_mapping_tag>::value,
typename Bounds::index_type>
make_stride(const Bounds& bnd) noexcept
{
return bnd.strides();
}
// Make a stride vector from bounds, assuming contiguous memory.
template <typename Bounds>
constexpr std::enable_if_t<
2015-11-24 15:49:03 -05:00
std::is_same<typename Bounds::mapping_type, contiguous_mapping_tag>::value,
typename Bounds::index_type>
make_stride(const Bounds& bnd) noexcept
{
auto extents = bnd.index_bounds();
typename Bounds::size_type stride[Bounds::rank] = {};
stride[Bounds::rank - 1] = 1;
for (std::size_t i = 1; i < Bounds::rank; ++i)
{
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
GSL_SUPPRESS(bounds.2) // NO-FORMAT: attribute
stride[Bounds::rank - i - 1] = stride[Bounds::rank - i] * extents[Bounds::rank - i];
}
2015-11-24 15:49:03 -05:00
return {stride};
}
template <typename BoundsSrc, typename BoundsDest>
2015-11-24 15:49:03 -05:00
void verifyBoundsReshape(const BoundsSrc& src, const BoundsDest& dest)
{
static_assert(is_bounds<BoundsSrc>::value && is_bounds<BoundsDest>::value,
"The src type and dest type must be bounds");
static_assert(std::is_same<typename BoundsSrc::mapping_type, contiguous_mapping_tag>::value,
"The source type must be a contiguous bounds");
static_assert(BoundsDest::static_size == dynamic_range ||
BoundsSrc::static_size == dynamic_range ||
BoundsDest::static_size == BoundsSrc::static_size,
"The source bounds must have same size as dest bounds");
Expects(src.size() == dest.size());
}
2015-08-20 21:09:14 -04:00
} // namespace details
template <typename Span>
class contiguous_span_iterator;
template <typename Span>
class general_span_iterator;
2015-08-20 21:09:14 -04:00
template <std::ptrdiff_t DimSize = dynamic_range>
struct dim_t
2015-08-20 21:09:14 -04:00
{
static const std::ptrdiff_t value = DimSize;
2015-08-20 21:09:14 -04:00
};
template <>
struct dim_t<dynamic_range>
2015-08-20 21:09:14 -04:00
{
static const std::ptrdiff_t value = dynamic_range;
const std::ptrdiff_t dvalue;
constexpr dim_t(std::ptrdiff_t size) noexcept : dvalue(size) {}
2015-08-20 21:09:14 -04:00
};
template <std::ptrdiff_t N, class = std::enable_if_t<(N >= 0)>>
constexpr dim_t<N> dim() noexcept
{
return dim_t<N>();
}
template <std::ptrdiff_t N = dynamic_range, class = std::enable_if_t<N == dynamic_range>>
constexpr dim_t<N> dim(std::ptrdiff_t n) noexcept
{
return dim_t<>(n);
}
2015-11-24 15:49:03 -05:00
template <typename ValueType, std::ptrdiff_t FirstDimension = dynamic_range,
std::ptrdiff_t... RestDimensions>
2016-02-24 13:29:29 -05:00
class multi_span;
2017-02-13 15:11:45 -05:00
template <typename ValueType, std::size_t Rank>
class strided_span;
2015-08-20 21:09:14 -04:00
namespace details
{
template <typename T, typename = std::true_type>
struct SpanTypeTraits
{
using value_type = T;
2017-02-13 15:11:45 -05:00
using size_type = std::size_t;
};
template <typename Traits>
2015-11-24 15:49:03 -05:00
struct SpanTypeTraits<Traits, typename std::is_reference<typename Traits::span_traits&>::type>
{
using value_type = typename Traits::span_traits::value_type;
using size_type = typename Traits::span_traits::size_type;
};
template <typename T, std::ptrdiff_t... Ranks>
2015-11-24 15:49:03 -05:00
struct SpanArrayTraits
{
2016-02-24 13:29:29 -05:00
using type = multi_span<T, Ranks...>;
using value_type = T;
using bounds_type = static_bounds<Ranks...>;
using pointer = T*;
using reference = T&;
};
template <typename T, std::ptrdiff_t N, std::ptrdiff_t... Ranks>
2015-11-24 15:49:03 -05:00
struct SpanArrayTraits<T[N], Ranks...> : SpanArrayTraits<T, Ranks..., N>
{
};
template <typename BoundsType>
BoundsType newBoundsHelperImpl(std::ptrdiff_t totalSize, std::true_type) // dynamic size
{
2015-11-24 15:49:03 -05:00
Expects(totalSize >= 0 && totalSize <= PTRDIFF_MAX);
return BoundsType{totalSize};
}
template <typename BoundsType>
BoundsType newBoundsHelperImpl(std::ptrdiff_t totalSize, std::false_type) // static size
{
2015-11-24 15:49:03 -05:00
Expects(BoundsType::static_size <= totalSize);
return {};
}
template <typename BoundsType>
BoundsType newBoundsHelper(std::ptrdiff_t totalSize)
{
static_assert(BoundsType::dynamic_rank <= 1, "dynamic rank must less or equal to 1");
2015-11-24 15:49:03 -05:00
return newBoundsHelperImpl<BoundsType>(
totalSize, std::integral_constant<bool, BoundsType::dynamic_rank == 1>());
}
2015-11-24 15:49:03 -05:00
struct Sep
{
};
template <typename T, typename... Args>
T static_as_multi_span_helper(Sep, Args... args)
{
2015-11-24 15:49:03 -05:00
return T{narrow_cast<typename T::size_type>(args)...};
}
template <typename T, typename Arg, typename... Args>
2015-11-24 15:49:03 -05:00
std::enable_if_t<
!std::is_same<Arg, dim_t<dynamic_range>>::value && !std::is_same<Arg, Sep>::value, T>
static_as_multi_span_helper(Arg, Args... args)
{
return static_as_multi_span_helper<T>(args...);
}
template <typename T, typename... Args>
T static_as_multi_span_helper(dim_t<dynamic_range> val, Args... args)
{
return static_as_multi_span_helper<T>(args..., val.dvalue);
}
2015-11-24 15:49:03 -05:00
template <typename... Dimensions>
struct static_as_multi_span_static_bounds_helper
{
using type = static_bounds<(Dimensions::value)...>;
};
template <typename T>
2016-03-01 15:11:41 -05:00
struct is_multi_span_oracle : std::false_type
2015-11-24 15:49:03 -05:00
{
};
template <typename ValueType, std::ptrdiff_t FirstDimension, std::ptrdiff_t... RestDimensions>
2016-07-20 16:17:47 -04:00
struct is_multi_span_oracle<multi_span<ValueType, FirstDimension, RestDimensions...>>
: std::true_type
2015-11-24 15:49:03 -05:00
{
};
template <typename ValueType, std::ptrdiff_t Rank>
2016-03-01 15:11:41 -05:00
struct is_multi_span_oracle<strided_span<ValueType, Rank>> : std::true_type
2015-11-24 15:49:03 -05:00
{
};
template <typename T>
2016-03-01 15:11:41 -05:00
struct is_multi_span : is_multi_span_oracle<std::remove_cv_t<T>>
2015-11-24 15:49:03 -05:00
{
};
} // namespace details
2015-08-20 21:09:14 -04:00
template <typename ValueType, std::ptrdiff_t FirstDimension, std::ptrdiff_t... RestDimensions>
2016-02-24 13:29:29 -05:00
class multi_span
2015-08-20 21:09:14 -04:00
{
2015-11-24 15:49:03 -05:00
// TODO do we still need this?
template <typename ValueType2, std::ptrdiff_t FirstDimension2,
std::ptrdiff_t... RestDimensions2>
2016-02-24 13:29:29 -05:00
friend class multi_span;
2015-08-20 21:09:14 -04:00
public:
2015-11-12 15:48:49 -05:00
using bounds_type = static_bounds<FirstDimension, RestDimensions...>;
2017-02-13 15:11:45 -05:00
static const std::size_t Rank = bounds_type::rank;
using size_type = typename bounds_type::size_type;
using index_type = typename bounds_type::index_type;
using value_type = ValueType;
using const_value_type = std::add_const_t<value_type>;
2015-11-12 15:48:49 -05:00
using pointer = std::add_pointer_t<value_type>;
using reference = std::add_lvalue_reference_t<value_type>;
2016-02-24 13:29:29 -05:00
using iterator = contiguous_span_iterator<multi_span>;
using const_span = multi_span<const_value_type, FirstDimension, RestDimensions...>;
using const_iterator = contiguous_span_iterator<const_span>;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
2015-11-24 15:49:03 -05:00
using sliced_type =
2016-02-24 13:29:29 -05:00
std::conditional_t<Rank == 1, value_type, multi_span<value_type, RestDimensions...>>;
private:
2015-11-24 15:49:03 -05:00
pointer data_;
bounds_type bounds_;
friend iterator;
friend const_iterator;
2015-08-20 21:09:14 -04:00
public:
2015-11-24 15:49:03 -05:00
// default constructor - same as constructing from nullptr_t
GSL_SUPPRESS(type.6) // NO-FORMAT: attribute // TODO: false positive
constexpr multi_span() noexcept
: multi_span(nullptr, bounds_type{})
{
2015-11-24 15:49:03 -05:00
static_assert(bounds_type::dynamic_rank != 0 ||
(bounds_type::dynamic_rank == 0 && bounds_type::static_size == 0),
2016-02-24 13:29:29 -05:00
"Default construction of multi_span<T> only possible "
2015-11-24 15:49:03 -05:00
"for dynamic or fixed, zero-length spans.");
}
2016-02-24 13:29:29 -05:00
// construct from nullptr - get an empty multi_span
GSL_SUPPRESS(type.6) // NO-FORMAT: attribute // TODO: false positive
constexpr multi_span(std::nullptr_t) noexcept
: multi_span(nullptr, bounds_type{})
2015-11-24 15:49:03 -05:00
{
static_assert(bounds_type::dynamic_rank != 0 ||
(bounds_type::dynamic_rank == 0 && bounds_type::static_size == 0),
2016-02-24 13:29:29 -05:00
"nullptr_t construction of multi_span<T> only possible "
2015-11-24 15:49:03 -05:00
"for dynamic or fixed, zero-length spans.");
}
2015-08-20 21:09:14 -04:00
2015-11-24 15:49:03 -05:00
// construct from nullptr with size of 0 (helps with template function calls)
template <class IntType, typename = std::enable_if_t<std::is_integral<IntType>::value>>
// GSL_SUPPRESS(type.6) // NO-FORMAT: attribute // TODO: false positive // TODO: parser bug
constexpr multi_span(std::nullptr_t, IntType size) : multi_span(nullptr, bounds_type{})
{
2015-11-24 15:49:03 -05:00
static_assert(bounds_type::dynamic_rank != 0 ||
(bounds_type::dynamic_rank == 0 && bounds_type::static_size == 0),
2016-02-24 13:29:29 -05:00
"nullptr_t construction of multi_span<T> only possible "
2015-11-24 15:49:03 -05:00
"for dynamic or fixed, zero-length spans.");
Expects(size == 0);
}
2015-08-20 21:09:14 -04:00
2015-11-24 15:49:03 -05:00
// construct from a single element
GSL_SUPPRESS(type.6) // NO-FORMAT: attribute // TODO: false positive
constexpr multi_span(reference data) noexcept
: multi_span(&data, bounds_type{1})
2015-11-24 15:49:03 -05:00
{
static_assert(bounds_type::dynamic_rank > 0 || bounds_type::static_size == 0 ||
bounds_type::static_size == 1,
"Construction from a single element only possible "
"for dynamic or fixed spans of length 0 or 1.");
}
2015-11-24 15:49:03 -05:00
// prevent constructing from temporaries for single-elements
2016-02-24 13:29:29 -05:00
constexpr multi_span(value_type&&) = delete;
2015-11-24 15:49:03 -05:00
// construct from pointer + length
GSL_SUPPRESS(type.6) // NO-FORMAT: attribute // TODO: false positive
constexpr multi_span(pointer ptr, size_type size)
: multi_span(ptr, bounds_type{size})
{}
2015-08-20 21:09:14 -04:00
2015-11-24 15:49:03 -05:00
// construct from pointer + length - multidimensional
constexpr multi_span(pointer data, bounds_type bounds)
: data_(data), bounds_(std::move(bounds))
{
2015-11-24 15:49:03 -05:00
Expects((bounds_.size() > 0 && data != nullptr) || bounds_.size() == 0);
}
2015-11-24 15:49:03 -05:00
// construct from begin,end pointer pair
template <typename Ptr,
typename = std::enable_if_t<std::is_convertible<Ptr, pointer>::value &&
details::LessThan<bounds_type::dynamic_rank, 2>::value>>
2016-02-24 13:29:29 -05:00
constexpr multi_span(pointer begin, Ptr end)
2016-07-20 16:17:47 -04:00
: multi_span(begin,
details::newBoundsHelper<bounds_type>(static_cast<pointer>(end) - begin))
{
2015-11-24 15:49:03 -05:00
Expects(begin != nullptr && end != nullptr && begin <= static_cast<pointer>(end));
}
2015-11-24 15:49:03 -05:00
// construct from n-dimensions static array
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t N, typename Helper = details::SpanArrayTraits<T, N>>
2016-02-24 13:29:29 -05:00
constexpr multi_span(T (&arr)[N])
: multi_span(reinterpret_cast<pointer>(arr), bounds_type{typename Helper::bounds_type{}})
{
2016-07-20 16:17:47 -04:00
static_assert(std::is_convertible<typename Helper::value_type(*)[], value_type(*)[]>::value,
"Cannot convert from source type to target multi_span type.");
2015-11-24 15:49:03 -05:00
static_assert(std::is_convertible<typename Helper::bounds_type, bounds_type>::value,
2016-02-24 13:29:29 -05:00
"Cannot construct a multi_span from an array with fewer elements.");
}
2015-08-20 21:09:14 -04:00
2015-11-24 15:49:03 -05:00
// construct from n-dimensions dynamic array (e.g. new int[m][4])
// (precedence will be lower than the 1-dimension pointer)
template <typename T, typename Helper = details::SpanArrayTraits<T, dynamic_range>>
2016-02-24 13:29:29 -05:00
constexpr multi_span(T* const& data, size_type size)
: multi_span(reinterpret_cast<pointer>(data), typename Helper::bounds_type{size})
{
2016-07-20 16:17:47 -04:00
static_assert(std::is_convertible<typename Helper::value_type(*)[], value_type(*)[]>::value,
"Cannot convert from source type to target multi_span type.");
}
2015-11-24 15:49:03 -05:00
// construct from std::array
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t N>
2016-07-20 16:17:47 -04:00
constexpr multi_span(std::array<T, N>& arr)
: multi_span(arr.data(), bounds_type{static_bounds<N>{}})
{
2015-11-24 15:49:03 -05:00
static_assert(
2016-07-20 16:17:47 -04:00
std::is_convertible<T(*)[], typename std::remove_const_t<value_type>(*)[]>::value,
2016-02-24 13:29:29 -05:00
"Cannot convert from source type to target multi_span type.");
2015-11-24 15:49:03 -05:00
static_assert(std::is_convertible<static_bounds<N>, bounds_type>::value,
2016-02-24 13:29:29 -05:00
"You cannot construct a multi_span from a std::array of smaller size.");
}
2015-11-24 15:49:03 -05:00
// construct from const std::array
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t N>
constexpr multi_span(const std::array<T, N>& arr)
: multi_span(arr.data(), bounds_type{static_bounds<N>{}})
{
static_assert(
std::is_convertible<T(*)[], typename std::remove_const_t<value_type>(*)[]>::value,
"Cannot convert from source type to target multi_span type.");
2015-11-24 15:49:03 -05:00
static_assert(std::is_convertible<static_bounds<N>, bounds_type>::value,
2016-02-24 13:29:29 -05:00
"You cannot construct a multi_span from a std::array of smaller size.");
}
2015-11-24 15:49:03 -05:00
// prevent constructing from temporary std::array
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t N>
2016-02-24 13:29:29 -05:00
constexpr multi_span(std::array<T, N>&& arr) = delete;
2015-11-24 15:49:03 -05:00
// construct from containers
// future: could use contiguous_iterator_traits to identify only contiguous containers
// type-requirements: container must have .size(), operator[] which are value_type compatible
template <typename Cont, typename DataType = typename Cont::value_type,
typename = std::enable_if_t<
2016-03-01 15:11:41 -05:00
!details::is_multi_span<Cont>::value &&
2015-11-24 15:49:03 -05:00
std::is_convertible<DataType (*)[], value_type (*)[]>::value &&
std::is_same<std::decay_t<decltype(std::declval<Cont>().size(),
*std::declval<Cont>().data())>,
DataType>::value>>
2016-02-24 13:29:29 -05:00
constexpr multi_span(Cont& cont)
: multi_span(static_cast<pointer>(cont.data()),
2016-07-20 16:17:47 -04:00
details::newBoundsHelper<bounds_type>(narrow_cast<size_type>(cont.size())))
{}
2015-11-24 15:49:03 -05:00
// prevent constructing from temporary containers
template <typename Cont, typename DataType = typename Cont::value_type,
typename = std::enable_if_t<
2016-03-01 15:11:41 -05:00
!details::is_multi_span<Cont>::value &&
2015-11-24 15:49:03 -05:00
std::is_convertible<DataType (*)[], value_type (*)[]>::value &&
std::is_same<std::decay_t<decltype(std::declval<Cont>().size(),
*std::declval<Cont>().data())>,
DataType>::value>>
2016-02-24 13:29:29 -05:00
explicit constexpr multi_span(Cont&& cont) = delete;
2015-11-24 15:49:03 -05:00
2016-02-24 13:29:29 -05:00
// construct from a convertible multi_span
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename OtherBounds = static_bounds<OtherDimensions...>,
typename = std::enable_if_t<std::is_convertible<OtherValueType, ValueType>::value &&
std::is_convertible<OtherBounds, bounds_type>::value>>
constexpr multi_span(multi_span<OtherValueType, OtherDimensions...> other)
: data_(other.data_), bounds_(other.bounds_)
{}
2017-07-14 07:40:27 -04:00
// trivial copy and move
2016-02-24 13:29:29 -05:00
constexpr multi_span(const multi_span&) = default;
2017-07-14 07:40:27 -04:00
constexpr multi_span(multi_span&&) = default;
2015-11-24 15:49:03 -05:00
2017-07-14 07:40:27 -04:00
// trivial assignment
2016-02-24 13:29:29 -05:00
constexpr multi_span& operator=(const multi_span&) = default;
2017-07-14 07:40:27 -04:00
constexpr multi_span& operator=(multi_span&&) = default;
2015-11-24 15:49:03 -05:00
2016-02-24 13:29:29 -05:00
// first() - extract the first Count elements into a new multi_span
2015-11-24 15:49:03 -05:00
template <std::ptrdiff_t Count>
constexpr multi_span<ValueType, Count> first() const
{
2015-11-24 15:49:03 -05:00
static_assert(Count >= 0, "Count must be >= 0.");
static_assert(bounds_type::static_size == dynamic_range ||
Count <= bounds_type::static_size,
"Count is out of bounds.");
Expects(bounds_type::static_size != dynamic_range || Count <= this->size());
return {this->data(), Count};
}
2016-02-24 13:29:29 -05:00
// first() - extract the first count elements into a new multi_span
constexpr multi_span<ValueType, dynamic_range> first(size_type count) const
{
2015-11-24 15:49:03 -05:00
Expects(count >= 0 && count <= this->size());
return {this->data(), count};
}
2016-02-24 13:29:29 -05:00
// last() - extract the last Count elements into a new multi_span
2015-11-24 15:49:03 -05:00
template <std::ptrdiff_t Count>
constexpr multi_span<ValueType, Count> last() const
{
2015-11-24 15:49:03 -05:00
static_assert(Count >= 0, "Count must be >= 0.");
static_assert(bounds_type::static_size == dynamic_range ||
Count <= bounds_type::static_size,
"Count is out of bounds.");
Expects(bounds_type::static_size != dynamic_range || Count <= this->size());
return {this->data() + this->size() - Count, Count};
}
2016-02-24 13:29:29 -05:00
// last() - extract the last count elements into a new multi_span
constexpr multi_span<ValueType, dynamic_range> last(size_type count) const
{
2015-11-24 15:49:03 -05:00
Expects(count >= 0 && count <= this->size());
return {this->data() + this->size() - count, count};
}
2015-11-24 15:49:03 -05:00
// subspan() - create a subview of Count elements starting at Offset
template <std::ptrdiff_t Offset, std::ptrdiff_t Count>
constexpr multi_span<ValueType, Count> subspan() const
{
2015-11-24 15:49:03 -05:00
static_assert(Count >= 0, "Count must be >= 0.");
static_assert(Offset >= 0, "Offset must be >= 0.");
static_assert(bounds_type::static_size == dynamic_range ||
((Offset <= bounds_type::static_size) &&
Count <= bounds_type::static_size - Offset),
2016-02-24 13:29:29 -05:00
"You must describe a sub-range within bounds of the multi_span.");
2015-11-24 15:49:03 -05:00
Expects(bounds_type::static_size != dynamic_range ||
(Offset <= this->size() && Count <= this->size() - Offset));
return {this->data() + Offset, Count};
}
2015-11-24 15:49:03 -05:00
// subspan() - create a subview of count elements starting at offset
// supplying dynamic_range for count will consume all available elements from offset
constexpr multi_span<ValueType, dynamic_range> subspan(size_type offset,
size_type count = dynamic_range) const
{
2015-11-24 15:49:03 -05:00
Expects((offset >= 0 && offset <= this->size()) &&
(count == dynamic_range || (count <= this->size() - offset)));
return {this->data() + offset, count == dynamic_range ? this->length() - offset : count};
}
2016-02-24 13:29:29 -05:00
// section - creates a non-contiguous, strided multi_span from a contiguous one
constexpr strided_span<ValueType, Rank> section(index_type origin,
index_type extents) const
{
const size_type size = this->bounds().total_size() - this->bounds().linearize(origin);
2015-11-24 15:49:03 -05:00
return {&this->operator[](origin), size,
strided_bounds<Rank>{extents, details::make_stride(bounds())}};
}
2016-02-24 13:29:29 -05:00
// length of the multi_span in elements
constexpr size_type size() const noexcept { return bounds_.size(); }
2016-02-24 13:29:29 -05:00
// length of the multi_span in elements
constexpr size_type length() const noexcept { return this->size(); }
2015-11-24 15:49:03 -05:00
2016-02-24 13:29:29 -05:00
// length of the multi_span in bytes
constexpr size_type size_bytes() const noexcept
{
return narrow_cast<size_type>(sizeof(value_type)) * this->size();
}
2015-11-24 15:49:03 -05:00
2016-02-24 13:29:29 -05:00
// length of the multi_span in bytes
constexpr size_type length_bytes() const noexcept { return this->size_bytes(); }
2015-11-24 15:49:03 -05:00
constexpr bool empty() const noexcept { return this->size() == 0; }
2015-11-24 15:49:03 -05:00
static constexpr std::size_t rank() { return Rank; }
2017-02-13 15:11:45 -05:00
template <std::size_t Dim = 0>
constexpr size_type extent() const noexcept
{
2015-11-24 15:49:03 -05:00
static_assert(Dim < Rank,
"Dimension should be less than rank (dimension count starts from 0).");
return bounds_.template extent<Dim>();
}
2015-11-24 15:49:03 -05:00
template <typename IntType>
constexpr size_type extent(IntType dim) const
{
2015-11-24 15:49:03 -05:00
return bounds_.extent(dim);
}
constexpr bounds_type bounds() const noexcept { return bounds_; }
2015-11-24 15:49:03 -05:00
constexpr pointer data() const noexcept { return data_; }
2015-11-24 15:49:03 -05:00
template <typename FirstIndex>
constexpr reference operator()(FirstIndex idx)
{
return this->operator[](narrow_cast<std::ptrdiff_t>(idx));
}
2015-11-24 15:49:03 -05:00
template <typename FirstIndex, typename... OtherIndices>
constexpr reference operator()(FirstIndex firstIndex, OtherIndices... indices)
{
const index_type idx = {narrow_cast<std::ptrdiff_t>(firstIndex),
narrow_cast<std::ptrdiff_t>(indices)...};
2015-11-24 15:49:03 -05:00
return this->operator[](idx);
}
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
constexpr reference operator[](const index_type& idx) const
{
2015-11-24 15:49:03 -05:00
return data_[bounds_.linearize(idx)];
}
2015-11-24 15:49:03 -05:00
template <bool Enabled = (Rank > 1), typename Ret = std::enable_if_t<Enabled, sliced_type>>
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
constexpr Ret operator[](size_type idx) const
{
Expects(idx >= 0 && idx < bounds_.size()); // index is out of bounds of the array
2015-11-24 15:49:03 -05:00
const size_type ridx = idx * bounds_.stride();
// index is out of bounds of the underlying data
Expects(ridx < bounds_.total_size());
return Ret{data_ + ridx, bounds_.slice()};
}
constexpr iterator begin() const noexcept { return iterator{this, true}; }
2015-11-24 15:49:03 -05:00
constexpr iterator end() const noexcept { return iterator{this, false}; }
2015-11-24 15:49:03 -05:00
GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
constexpr const_iterator cbegin() const noexcept
{
2015-11-24 15:49:03 -05:00
return const_iterator{reinterpret_cast<const const_span*>(this), true};
}
constexpr const_iterator cend() const noexcept
{
2015-11-24 15:49:03 -05:00
return const_iterator{reinterpret_cast<const const_span*>(this), false};
}
constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator{end()}; }
constexpr reverse_iterator rend() const noexcept { return reverse_iterator{begin()}; }
constexpr const_reverse_iterator crbegin() const noexcept
{
2015-11-24 15:49:03 -05:00
return const_reverse_iterator{cend()};
}
constexpr const_reverse_iterator crend() const noexcept
{
2015-11-24 15:49:03 -05:00
return const_reverse_iterator{cbegin()};
}
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>,
std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator==(const multi_span<OtherValueType, OtherDimensions...>& other) const
{
2015-11-24 15:49:03 -05:00
return bounds_.size() == other.bounds_.size() &&
(data_ == other.data_ || std::equal(this->begin(), this->end(), other.begin()));
}
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>,
std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator!=(const multi_span<OtherValueType, OtherDimensions...>& other) const
{
return !(*this == other);
}
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>,
std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator<(const multi_span<OtherValueType, OtherDimensions...>& other) const
{
return std::lexicographical_compare(this->begin(), this->end(), other.begin(), other.end());
}
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>,
std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator<=(const multi_span<OtherValueType, OtherDimensions...>& other) const
{
return !(other < *this);
}
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>,
std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator>(const multi_span<OtherValueType, OtherDimensions...>& other) const
noexcept
{
return (other < *this);
}
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>,
std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator>=(const multi_span<OtherValueType, OtherDimensions...>& other) const
{
return !(*this < other);
}
2015-08-20 21:09:14 -04:00
};
2015-11-24 15:49:03 -05:00
//
// Free functions for manipulating spans
//
2016-02-24 13:29:29 -05:00
// reshape a multi_span into a different dimensionality
2015-11-24 15:49:03 -05:00
// DimCount and Enabled here are workarounds for a bug in MSVC 2015
2017-02-13 15:11:45 -05:00
template <typename SpanType, typename... Dimensions2, std::size_t DimCount = sizeof...(Dimensions2),
2016-08-01 16:10:02 -04:00
bool Enabled = (DimCount > 0), typename = std::enable_if_t<Enabled>>
constexpr auto as_multi_span(SpanType s, Dimensions2... dims)
2016-08-01 16:10:02 -04:00
-> multi_span<typename SpanType::value_type, Dimensions2::value...>
2015-11-24 15:49:03 -05:00
{
2016-03-01 15:11:41 -05:00
static_assert(details::is_multi_span<SpanType>::value,
"Variadic as_multi_span() is for reshaping existing spans.");
2015-11-24 15:49:03 -05:00
using BoundsType =
2016-02-24 13:29:29 -05:00
typename multi_span<typename SpanType::value_type, (Dimensions2::value)...>::bounds_type;
const auto tobounds = details::static_as_multi_span_helper<BoundsType>(dims..., details::Sep{});
2015-11-24 15:49:03 -05:00
details::verifyBoundsReshape(s.bounds(), tobounds);
return {s.data(), tobounds};
}
2016-02-24 13:29:29 -05:00
// convert a multi_span<T> to a multi_span<const byte>
2015-11-24 15:49:03 -05:00
template <typename U, std::ptrdiff_t... Dimensions>
multi_span<const byte, dynamic_range> as_bytes(multi_span<U, Dimensions...> s) noexcept
2015-11-24 15:49:03 -05:00
{
static_assert(std::is_trivial<std::decay_t<U>>::value,
2016-02-24 13:29:29 -05:00
"The value_type of multi_span must be a trivial type.");
2015-11-24 15:49:03 -05:00
return {reinterpret_cast<const byte*>(s.data()), s.size_bytes()};
}
2016-02-24 13:29:29 -05:00
// convert a multi_span<T> to a multi_span<byte> (a writeable byte multi_span)
2015-11-24 15:49:03 -05:00
// this is not currently a portable function that can be relied upon to work
// on all implementations. It should be considered an experimental extension
// to the standard GSL interface.
template <typename U, std::ptrdiff_t... Dimensions>
multi_span<byte> as_writeable_bytes(multi_span<U, Dimensions...> s) noexcept
2015-11-24 15:49:03 -05:00
{
static_assert(std::is_trivial<std::decay_t<U>>::value,
2016-02-24 13:29:29 -05:00
"The value_type of multi_span must be a trivial type.");
2015-11-24 15:49:03 -05:00
return {reinterpret_cast<byte*>(s.data()), s.size_bytes()};
}
2016-02-24 13:29:29 -05:00
// convert a multi_span<const byte> to a multi_span<const T>
2015-11-24 15:49:03 -05:00
// this is not currently a portable function that can be relied upon to work
// on all implementations. It should be considered an experimental extension
// to the standard GSL interface.
template <typename U, std::ptrdiff_t... Dimensions>
constexpr auto as_multi_span(multi_span<const byte, Dimensions...> s) -> multi_span<
2016-07-20 16:17:47 -04:00
const U, static_cast<std::ptrdiff_t>(
multi_span<const byte, Dimensions...>::bounds_type::static_size != dynamic_range
2017-02-13 15:11:45 -05:00
? (static_cast<std::size_t>(
2016-07-20 16:17:47 -04:00
multi_span<const byte, Dimensions...>::bounds_type::static_size) /
sizeof(U))
: dynamic_range)>
2015-11-24 15:49:03 -05:00
{
2016-02-24 13:29:29 -05:00
using ConstByteSpan = multi_span<const byte, Dimensions...>;
2015-11-24 15:49:03 -05:00
static_assert(
std::is_trivial<std::decay_t<U>>::value &&
(ConstByteSpan::bounds_type::static_size == dynamic_range ||
ConstByteSpan::bounds_type::static_size % narrow_cast<std::ptrdiff_t>(sizeof(U)) == 0),
"Target type must be a trivial type and its size must match the byte array size");
Expects((s.size_bytes() % narrow_cast<std::ptrdiff_t>(sizeof(U))) == 0 &&
(s.size_bytes() / narrow_cast<std::ptrdiff_t>(sizeof(U))) < PTRDIFF_MAX);
2015-11-24 15:49:03 -05:00
return {reinterpret_cast<const U*>(s.data()),
s.size_bytes() / narrow_cast<std::ptrdiff_t>(sizeof(U))};
}
2016-02-24 13:29:29 -05:00
// convert a multi_span<byte> to a multi_span<T>
2015-11-24 15:49:03 -05:00
// this is not currently a portable function that can be relied upon to work
// on all implementations. It should be considered an experimental extension
// to the standard GSL interface.
template <typename U, std::ptrdiff_t... Dimensions>
constexpr auto as_multi_span(multi_span<byte, Dimensions...> s)
2016-07-20 16:17:47 -04:00
-> multi_span<U, narrow_cast<std::ptrdiff_t>(
multi_span<byte, Dimensions...>::bounds_type::static_size != dynamic_range
? static_cast<std::size_t>(
multi_span<byte, Dimensions...>::bounds_type::static_size) /
sizeof(U)
: dynamic_range)>
2015-11-24 15:49:03 -05:00
{
2016-02-24 13:29:29 -05:00
using ByteSpan = multi_span<byte, Dimensions...>;
static_assert(std::is_trivial<std::decay_t<U>>::value &&
(ByteSpan::bounds_type::static_size == dynamic_range ||
ByteSpan::bounds_type::static_size % sizeof(U) == 0),
"Target type must be a trivial type and its size must match the byte array size");
2015-11-24 15:49:03 -05:00
Expects((s.size_bytes() % sizeof(U)) == 0);
2015-11-24 15:49:03 -05:00
return {reinterpret_cast<U*>(s.data()),
s.size_bytes() / narrow_cast<std::ptrdiff_t>(sizeof(U))};
}
template <typename T, std::ptrdiff_t... Dimensions>
constexpr auto as_multi_span(T* const& ptr, dim_t<Dimensions>... args)
2016-02-24 13:29:29 -05:00
-> multi_span<std::remove_all_extents_t<T>, Dimensions...>
2015-08-20 21:09:14 -04:00
{
2015-11-24 15:49:03 -05:00
return {reinterpret_cast<std::remove_all_extents_t<T>*>(ptr),
2016-08-01 16:10:02 -04:00
details::static_as_multi_span_helper<static_bounds<Dimensions...>>(args...,
details::Sep{})};
2015-08-20 21:09:14 -04:00
}
template <typename T>
constexpr auto as_multi_span(T* arr, std::ptrdiff_t len) ->
2015-11-24 15:49:03 -05:00
typename details::SpanArrayTraits<T, dynamic_range>::type
2015-08-20 21:09:14 -04:00
{
return {reinterpret_cast<std::remove_all_extents_t<T>*>(arr), len};
2015-08-20 21:09:14 -04:00
}
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t N>
constexpr auto as_multi_span(T (&arr)[N]) -> typename details::SpanArrayTraits<T, N>::type
2015-08-20 21:09:14 -04:00
{
return {arr};
2015-08-20 21:09:14 -04:00
}
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t N>
constexpr multi_span<const T, N> as_multi_span(const std::array<T, N>& arr)
2015-08-20 21:09:14 -04:00
{
return {arr};
2015-08-20 21:09:14 -04:00
}
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t N>
constexpr multi_span<const T, N> as_multi_span(const std::array<T, N>&&) = delete;
2015-08-20 21:09:14 -04:00
2017-02-13 15:11:45 -05:00
template <typename T, std::size_t N>
constexpr multi_span<T, N> as_multi_span(std::array<T, N>& arr)
2015-08-20 21:09:14 -04:00
{
return {arr};
2015-08-20 21:09:14 -04:00
}
template <typename T>
constexpr multi_span<T, dynamic_range> as_multi_span(T* begin, T* end)
2015-08-20 21:09:14 -04:00
{
return {begin, end};
2015-08-20 21:09:14 -04:00
}
template <typename Cont>
constexpr auto as_multi_span(Cont& arr) -> std::enable_if_t<
2016-03-01 15:11:41 -05:00
!details::is_multi_span<std::decay_t<Cont>>::value,
2016-02-24 13:29:29 -05:00
multi_span<std::remove_reference_t<decltype(arr.size(), *arr.data())>, dynamic_range>>
2015-08-20 21:09:14 -04:00
{
Expects(arr.size() < PTRDIFF_MAX);
2015-11-24 15:49:03 -05:00
return {arr.data(), narrow_cast<std::ptrdiff_t>(arr.size())};
2015-08-20 21:09:14 -04:00
}
template <typename Cont>
constexpr auto as_multi_span(Cont&& arr) -> std::enable_if_t<
2016-03-01 15:11:41 -05:00
!details::is_multi_span<std::decay_t<Cont>>::value,
2016-02-24 13:29:29 -05:00
multi_span<std::remove_reference_t<decltype(arr.size(), *arr.data())>, dynamic_range>> = delete;
2015-08-20 21:09:14 -04:00
// from basic_string which doesn't have nonconst .data() member like other contiguous containers
template <typename CharT, typename Traits, typename Allocator>
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
constexpr auto as_multi_span(std::basic_string<CharT, Traits, Allocator>& str)
2016-02-24 13:29:29 -05:00
-> multi_span<CharT, dynamic_range>
{
Expects(str.size() < PTRDIFF_MAX);
2015-11-24 15:49:03 -05:00
return {&str[0], narrow_cast<std::ptrdiff_t>(str.size())};
}
2015-11-24 15:49:03 -05:00
// strided_span is an extension that is not strictly part of the GSL at this time.
// It is kept here while the multidimensional interface is still being defined.
2017-02-13 15:11:45 -05:00
template <typename ValueType, std::size_t Rank>
2015-11-12 15:48:49 -05:00
class strided_span
2015-08-20 21:09:14 -04:00
{
2015-11-12 15:48:49 -05:00
public:
using bounds_type = strided_bounds<Rank>;
using size_type = typename bounds_type::size_type;
using index_type = typename bounds_type::index_type;
using value_type = ValueType;
using const_value_type = std::add_const_t<value_type>;
using pointer = std::add_pointer_t<value_type>;
using reference = std::add_lvalue_reference_t<value_type>;
using iterator = general_span_iterator<strided_span>;
using const_strided_span = strided_span<const_value_type, Rank>;
using const_iterator = general_span_iterator<const_strided_span>;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
2015-11-24 15:49:03 -05:00
using sliced_type =
std::conditional_t<Rank == 1, value_type, strided_span<value_type, Rank - 1>>;
2015-11-12 15:48:49 -05:00
private:
2015-11-24 15:49:03 -05:00
pointer data_;
bounds_type bounds_;
2015-11-12 15:48:49 -05:00
friend iterator;
friend const_iterator;
2017-02-13 15:11:45 -05:00
template <typename OtherValueType, std::size_t OtherRank>
friend class strided_span;
2015-08-20 21:09:14 -04:00
public:
// from raw data
2015-11-12 15:48:49 -05:00
constexpr strided_span(pointer ptr, size_type size, bounds_type bounds)
2015-11-24 15:49:03 -05:00
: data_(ptr), bounds_(std::move(bounds))
{
2015-11-24 15:49:03 -05:00
Expects((bounds_.size() > 0 && ptr != nullptr) || bounds_.size() == 0);
// Bounds cross data boundaries
Expects(this->bounds().total_size() <= size);
GSL_SUPPRESS(type.4) // NO-FORMAT: attribute // TODO: false positive
2015-11-24 15:49:03 -05:00
(void) size;
}
2015-11-12 15:48:49 -05:00
// from static array of size N
2015-11-24 15:49:03 -05:00
template <size_type N>
constexpr strided_span(value_type (&values)[N], bounds_type bounds)
: strided_span(values, N, std::move(bounds))
{}
2015-11-12 15:48:49 -05:00
// from array view
template <typename OtherValueType, std::ptrdiff_t... Dimensions,
2015-11-24 15:49:03 -05:00
bool Enabled1 = (sizeof...(Dimensions) == Rank),
bool Enabled2 = std::is_convertible<OtherValueType*, ValueType*>::value,
typename = std::enable_if_t<Enabled1 && Enabled2>>
2016-02-24 13:29:29 -05:00
constexpr strided_span(multi_span<OtherValueType, Dimensions...> av, bounds_type bounds)
2015-11-24 15:49:03 -05:00
: strided_span(av.data(), av.bounds().total_size(), std::move(bounds))
{}
2015-11-24 15:49:03 -05:00
// convertible
template <typename OtherValueType, typename = std::enable_if_t<std::is_convertible<
2015-11-24 15:49:03 -05:00
OtherValueType (*)[], value_type (*)[]>::value>>
2015-11-12 15:48:49 -05:00
constexpr strided_span(const strided_span<OtherValueType, Rank>& other)
2015-11-24 15:49:03 -05:00
: data_(other.data_), bounds_(other.bounds_)
{}
// convert from bytes
2015-11-12 15:48:49 -05:00
template <typename OtherValueType>
2015-11-24 15:49:03 -05:00
constexpr strided_span<
typename std::enable_if<std::is_same<value_type, const byte>::value, OtherValueType>::type,
Rank>
as_strided_span() const
{
2015-11-24 15:49:03 -05:00
static_assert((sizeof(OtherValueType) >= sizeof(value_type)) &&
(sizeof(OtherValueType) % sizeof(value_type) == 0),
"OtherValueType should have a size to contain a multiple of ValueTypes");
auto d = narrow_cast<size_type>(sizeof(OtherValueType) / sizeof(value_type));
const size_type size = this->bounds().total_size() / d;
Clang cl (#762) * Added c++17 test configurations for clang5.0 and clang6.0 * Fix #739 correct cppcorecheck warnings for clang-cl * Add clang-cl configurations * Corrections Appveyor; Temporarily disable msvc compilation for faster testing (#741) * Add path to clang-cl.exe (#741) * Escape backslash in path (#741) * Update vcpkg (#741) * Check vcpkg version; try without building vcpkg; use latest clang-cl from path (#741) * Fix blocks in ps script (#741) * Try accessing APPVEYOR_BUILD_FOLDER variable (#471) * Update span size() bug confirmation test for GCC 6.5 (#741) * MSVC flags to Clang-cl; disable c++98-compat and undefined macro warnings (#741) * Suppress clang warning on tests (missing-prototypes) (#741) * Fix clang warning -Wnewline-eof (#741) * Fix clang warning -Wdouble-promotion (#741) * Set linker explicitly * Clean condition statement * For Clang, fallback to the AppVeyor installed version of CMake * Fix clang warning -Wmissing-variable-declarations * Fallback to the MSVC linker until vcpkg has been updated * Revert "Fallback to the MSVC linker until vcpkg has been updated" This reverts commit 7263f3289e6e835c32fc7800d0c2d4e58bd21178. * Fix clang warning -Wunused-member-function * Fix clang warning -Wmissing-noreturn * Fix clang warning -Winvalid-noreturn on Windows * Add macro block end comment on large #if blocks * Workaround: fallback to mscv link.exe * Workaround: get msvc paths into PowerShell through intermediate file * Workaround: fix, remove "PATH=" from text * Workaround: try with full-path; and return user PATH * Workaround: fix, escape backslashes * Revert all since "Workaround: fallback to mscv link.exe" did not work on AppVeyor This reverts the commits: bda3d6a428e5d19e97375b2e575b0f51ff1b4bc0 97062933acfb6428535c0fdcab5d94371ce72bfc 0f4fb04bac9c2d091005b791294237250dbe0668 1b0c19afd154f4ffc5ef793014c1bc2324534fd0 a5739ea5f0cd7633527b5e5d3b16a9e3ade7149f * Suppress output of git pull; remove vcpkg from cache * Re-enable AppVeyor builds for all platforms * Correct typo Co-Authored-By: Farwaykorse <Farwaykorse@users.noreply.github.com> * Add Clang-cl 7.0.0 to the supported platforms * Revert "Fix clang warning -Wunused-member-function" This reverts commit 6fe1a4203501145ab4350b9152ecc11f3a30e49a. * Fix or locally suppress clang warning -Wunused-member-function * format touched code and correct comment * git pull --quiet * fix logic error in workaround * fix missing bracket * Suppress output of mkdir * Replace MSBuild with Ninja * Suppress output of 7z * Add architecture flags for Clang * Drop workaround for lld-link * 7-zip Overwrite and Alternative output suppression without suppressing errors Replaces 3c1c0794dd9a29908cc7c38f591bd3c7b4929677 * AppVeyor setup and CMake before build * reorder compiler configuration * remove unnecessary * remove -fno-strict-aliasing * remove -Wsign-conversion, since before v4.0 part of -Wconversion * -Wctor-dtor-privacy is GCC only * remove -Woverloaded-virtual part of -Wmost, part of -Wall * add -Wmissing-noreturn * remove the pragmas for -Wunused-member-function * Re-add MSBuild generator on AppVeyor * Print CMake commands * Add MSBuild toolset selection * Separate Architecture setting * clang-cl: add -Weverything * clang-cl -Wno-c++98-compat * clang-cl -Wno-c++98-compat-pedantic * clang-cl -Wno-missing-prototypes * clang-cl C++14 -Wno-unused-member-function * clang-cl -Wundef __GNUC__ * clang++: add -Weverything * clang++ -Wno-c++98-compat * clang++ -Wno-c++98-compat-pedantic * clang++ -Wno-missing-prototypes * clang++ -Wno-weak-vtables * clang++ C++14 -Wno-unused-member-function * clang++ fix -Wundef _MSC_VER * clang++ -Wno-padded * clang++ solve -Wdeprecated * Add AppleClang compiler target Since CMake v3.0 use of Clang for both is deprecated * clang++ v5.0 C++17 -Wno-undefined-func-template * Add VS2015 + LLVM/clang-cl to AppVeyor * Do not disable constexpr when compiling with clang-cl on Windows * Clean-up clang-only warnings (now under -Weverything) * Revert "Fix clang warning -Winvalid-noreturn on Windows" This reverts commit 2238c4760e86feebb2a18620b77312bd01055f61. * Suppress -Winvalid-noreturn for the MS STL noexception workaround * CMake: put preprocessor definition in target_compile_definitions * Solve compiler warning C4668: __GNUC__ not defined
2019-01-15 13:27:34 -05:00
GSL_SUPPRESS(type.3) // NO-FORMAT: attribute
2016-07-20 16:17:47 -04:00
return {const_cast<OtherValueType*>(reinterpret_cast<const OtherValueType*>(this->data())),
size,
bounds_type{resize_extent(this->bounds().index_bounds(), d),
resize_stride(this->bounds().strides(), d)}};
}
2015-11-12 15:48:49 -05:00
constexpr strided_span section(index_type origin, index_type extents) const
{
const size_type size = this->bounds().total_size() - this->bounds().linearize(origin);
2015-11-24 15:49:03 -05:00
return {&this->operator[](origin), size,
bounds_type{extents, details::make_stride(bounds())}};
}
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
constexpr reference operator[](const index_type& idx) const
{
2015-11-24 15:49:03 -05:00
return data_[bounds_.linearize(idx)];
2015-11-12 15:48:49 -05:00
}
template <bool Enabled = (Rank > 1), typename Ret = std::enable_if_t<Enabled, sliced_type>>
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
2015-11-12 15:48:49 -05:00
constexpr Ret operator[](size_type idx) const
{
2015-11-24 15:49:03 -05:00
Expects(idx < bounds_.size()); // index is out of bounds of the array
const size_type ridx = idx * bounds_.stride();
2015-11-12 15:48:49 -05:00
// index is out of bounds of the underlying data
2015-11-24 15:49:03 -05:00
Expects(ridx < bounds_.total_size());
return {data_ + ridx, bounds_.slice().total_size(), bounds_.slice()};
2015-11-12 15:48:49 -05:00
}
constexpr bounds_type bounds() const noexcept { return bounds_; }
2015-11-12 15:48:49 -05:00
2017-02-13 15:11:45 -05:00
template <std::size_t Dim = 0>
constexpr size_type extent() const noexcept
2015-11-12 15:48:49 -05:00
{
2015-11-24 15:49:03 -05:00
static_assert(Dim < Rank,
"dimension should be less than Rank (dimension count starts from 0)");
return bounds_.template extent<Dim>();
}
constexpr size_type size() const noexcept { return bounds_.size(); }
2015-11-12 15:48:49 -05:00
constexpr pointer data() const noexcept { return data_; }
2015-11-12 15:48:49 -05:00
constexpr bool empty() const noexcept { return this->size() == 0; }
constexpr explicit operator bool() const noexcept { return data_ != nullptr; }
2015-11-12 15:48:49 -05:00
2015-11-24 15:49:03 -05:00
constexpr iterator begin() const { return iterator{this, true}; }
2015-11-12 15:48:49 -05:00
2015-11-24 15:49:03 -05:00
constexpr iterator end() const { return iterator{this, false}; }
2015-11-12 15:48:49 -05:00
constexpr const_iterator cbegin() const
{
2015-11-24 15:49:03 -05:00
return const_iterator{reinterpret_cast<const const_strided_span*>(this), true};
2015-11-12 15:48:49 -05:00
}
constexpr const_iterator cend() const
{
2015-11-24 15:49:03 -05:00
return const_iterator{reinterpret_cast<const const_strided_span*>(this), false};
2015-11-12 15:48:49 -05:00
}
2015-11-24 15:49:03 -05:00
constexpr reverse_iterator rbegin() const { return reverse_iterator{end()}; }
2015-11-12 15:48:49 -05:00
2015-11-24 15:49:03 -05:00
constexpr reverse_iterator rend() const { return reverse_iterator{begin()}; }
2015-11-12 15:48:49 -05:00
2015-11-24 15:49:03 -05:00
constexpr const_reverse_iterator crbegin() const { return const_reverse_iterator{cend()}; }
2015-11-12 15:48:49 -05:00
2015-11-24 15:49:03 -05:00
constexpr const_reverse_iterator crend() const { return const_reverse_iterator{cbegin()}; }
2015-11-12 15:48:49 -05:00
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t OtherRank,
typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>,
std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator==(const strided_span<OtherValueType, OtherRank>& other) const
2015-11-12 15:48:49 -05:00
{
2015-11-24 15:49:03 -05:00
return bounds_.size() == other.bounds_.size() &&
(data_ == other.data_ || std::equal(this->begin(), this->end(), other.begin()));
2015-11-12 15:48:49 -05:00
}
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t OtherRank,
typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>,
std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator!=(const strided_span<OtherValueType, OtherRank>& other) const
2015-11-12 15:48:49 -05:00
{
return !(*this == other);
}
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t OtherRank,
typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>,
std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator<(const strided_span<OtherValueType, OtherRank>& other) const
2015-11-12 15:48:49 -05:00
{
return std::lexicographical_compare(this->begin(), this->end(), other.begin(), other.end());
}
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t OtherRank,
typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>,
std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator<=(const strided_span<OtherValueType, OtherRank>& other) const
2015-11-12 15:48:49 -05:00
{
return !(other < *this);
}
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t OtherRank,
typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>,
std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator>(const strided_span<OtherValueType, OtherRank>& other) const
2015-11-12 15:48:49 -05:00
{
return (other < *this);
}
2015-11-24 15:49:03 -05:00
template <typename OtherValueType, std::ptrdiff_t OtherRank,
typename = std::enable_if_t<std::is_same<std::remove_cv_t<value_type>,
std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator>=(const strided_span<OtherValueType, OtherRank>& other) const
2015-11-12 15:48:49 -05:00
{
return !(*this < other);
}
private:
static index_type resize_extent(const index_type& extent, std::ptrdiff_t d)
{
// The last dimension of the array needs to contain a multiple of new type elements
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
Expects(extent[Rank - 1] >= d && (extent[Rank - 1] % d == 0));
index_type ret = extent;
2015-11-12 15:48:49 -05:00
ret[Rank - 1] /= d;
return ret;
}
template <bool Enabled = (Rank == 1), typename = std::enable_if_t<Enabled>>
static index_type resize_stride(const index_type& strides, std::ptrdiff_t, void* = nullptr)
{
// Only strided arrays with regular strides can be resized
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
Expects(strides[Rank - 1] == 1);
return strides;
}
template <bool Enabled = (Rank > 1), typename = std::enable_if_t<Enabled>>
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
static index_type resize_stride(const index_type& strides, std::ptrdiff_t d)
{
// Only strided arrays with regular strides can be resized
Expects(strides[Rank - 1] == 1);
// The strides must have contiguous chunks of
// memory that can contain a multiple of new type elements
Expects(strides[Rank - 2] >= d && (strides[Rank - 2] % d == 0));
for (std::size_t i = Rank - 1; i > 0; --i)
{
// Only strided arrays with regular strides can be resized
Expects((strides[i - 1] >= strides[i]) && (strides[i - 1] % strides[i] == 0));
2015-11-12 15:48:49 -05:00
}
index_type ret = strides / d;
2015-11-12 15:48:49 -05:00
ret[Rank - 1] = 1;
return ret;
}
2015-08-20 21:09:14 -04:00
};
template <class Span>
2015-11-24 15:49:03 -05:00
class contiguous_span_iterator
2015-08-20 21:09:14 -04:00
{
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = typename Span::value_type;
using difference_type = std::ptrdiff_t;
using pointer = value_type*;
using reference = value_type&;
2015-08-20 21:09:14 -04:00
private:
template <typename ValueType, std::ptrdiff_t FirstDimension, std::ptrdiff_t... RestDimensions>
2016-02-24 13:29:29 -05:00
friend class multi_span;
2015-11-24 15:49:03 -05:00
pointer data_;
const Span* m_validator;
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
void validateThis() const {
// iterator is out of range of the array
2015-11-24 15:49:03 -05:00
Expects(data_ >= m_validator->data_ && data_ < m_validator->data_ + m_validator->size());
}
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
2015-11-24 15:49:03 -05:00
contiguous_span_iterator(const Span* container, bool isbegin)
: data_(isbegin ? container->data_ : container->data_ + container->size())
, m_validator(container)
{}
2015-11-24 15:49:03 -05:00
2015-08-20 21:09:14 -04:00
public:
reference operator*() const
{
validateThis();
2015-11-24 15:49:03 -05:00
return *data_;
}
pointer operator->() const
{
validateThis();
2015-11-24 15:49:03 -05:00
return data_;
}
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
contiguous_span_iterator& operator++() noexcept
{
2015-11-24 15:49:03 -05:00
++data_;
return *this;
}
contiguous_span_iterator operator++(int) noexcept
{
auto ret = *this;
++(*this);
return ret;
}
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
contiguous_span_iterator& operator--() noexcept
{
2015-11-24 15:49:03 -05:00
--data_;
return *this;
}
contiguous_span_iterator operator--(int) noexcept
{
auto ret = *this;
--(*this);
return ret;
}
contiguous_span_iterator operator+(difference_type n) const noexcept
{
2015-11-24 15:49:03 -05:00
contiguous_span_iterator ret{*this};
return ret += n;
}
contiguous_span_iterator& operator+=(difference_type n) noexcept
{
2015-11-24 15:49:03 -05:00
data_ += n;
return *this;
}
contiguous_span_iterator operator-(difference_type n) const noexcept
{
2015-11-24 15:49:03 -05:00
contiguous_span_iterator ret{*this};
return ret -= n;
}
contiguous_span_iterator& operator-=(difference_type n) { return *this += -n; }
difference_type operator-(const contiguous_span_iterator& rhs) const
{
Expects(m_validator == rhs.m_validator);
2015-11-24 15:49:03 -05:00
return data_ - rhs.data_;
}
reference operator[](difference_type n) const { return *(*this + n); }
bool operator==(const contiguous_span_iterator& rhs) const
{
Expects(m_validator == rhs.m_validator);
2015-11-24 15:49:03 -05:00
return data_ == rhs.data_;
}
bool operator!=(const contiguous_span_iterator& rhs) const { return !(*this == rhs); }
bool operator<(const contiguous_span_iterator& rhs) const
{
Expects(m_validator == rhs.m_validator);
2015-11-24 15:49:03 -05:00
return data_ < rhs.data_;
}
bool operator<=(const contiguous_span_iterator& rhs) const { return !(rhs < *this); }
bool operator>(const contiguous_span_iterator& rhs) const { return rhs < *this; }
bool operator>=(const contiguous_span_iterator& rhs) const { return !(rhs > *this); }
void swap(contiguous_span_iterator& rhs) noexcept
{
2015-11-24 15:49:03 -05:00
std::swap(data_, rhs.data_);
std::swap(m_validator, rhs.m_validator);
}
2015-08-20 21:09:14 -04:00
};
template <typename Span>
2015-11-24 15:49:03 -05:00
contiguous_span_iterator<Span> operator+(typename contiguous_span_iterator<Span>::difference_type n,
const contiguous_span_iterator<Span>& rhs) noexcept
2015-08-20 21:09:14 -04:00
{
return rhs + n;
2015-08-20 21:09:14 -04:00
}
template <typename Span>
class general_span_iterator {
2015-08-20 21:09:14 -04:00
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = typename Span::value_type;
using difference_type = std::ptrdiff_t;
using pointer = value_type*;
using reference = value_type&;
2015-11-24 15:49:03 -05:00
2015-08-20 21:09:14 -04:00
private:
2017-02-13 15:11:45 -05:00
template <typename ValueType, std::size_t Rank>
2015-11-12 15:48:49 -05:00
friend class strided_span;
2015-11-24 15:49:03 -05:00
2015-11-12 15:48:49 -05:00
const Span* m_container;
typename Span::bounds_type::iterator m_itr;
2015-11-24 15:49:03 -05:00
general_span_iterator(const Span* container, bool isbegin)
: m_container(container)
, m_itr(isbegin ? m_container->bounds().begin() : m_container->bounds().end())
{}
2015-11-24 15:49:03 -05:00
public:
reference operator*() noexcept { return (*m_container)[*m_itr]; }
pointer operator->() noexcept { return &(*m_container)[*m_itr]; }
general_span_iterator& operator++() noexcept
{
++m_itr;
return *this;
}
general_span_iterator operator++(int) noexcept
{
auto ret = *this;
++(*this);
return ret;
}
general_span_iterator& operator--() noexcept
{
--m_itr;
return *this;
}
general_span_iterator operator--(int) noexcept
{
auto ret = *this;
--(*this);
return ret;
}
general_span_iterator operator+(difference_type n) const noexcept
{
2015-11-24 15:49:03 -05:00
general_span_iterator ret{*this};
return ret += n;
}
general_span_iterator& operator+=(difference_type n) noexcept
{
m_itr += n;
return *this;
}
general_span_iterator operator-(difference_type n) const noexcept
{
2015-11-24 15:49:03 -05:00
general_span_iterator ret{*this};
return ret -= n;
}
general_span_iterator& operator-=(difference_type n) noexcept { return *this += -n; }
difference_type operator-(const general_span_iterator& rhs) const
{
Expects(m_container == rhs.m_container);
return m_itr - rhs.m_itr;
}
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
value_type operator[](difference_type n) const { return (*m_container)[m_itr[n]]; }
bool operator==(const general_span_iterator& rhs) const
{
Expects(m_container == rhs.m_container);
return m_itr == rhs.m_itr;
}
bool operator!=(const general_span_iterator& rhs) const { return !(*this == rhs); }
bool operator<(const general_span_iterator& rhs) const
{
Expects(m_container == rhs.m_container);
return m_itr < rhs.m_itr;
}
bool operator<=(const general_span_iterator& rhs) const { return !(rhs < *this); }
bool operator>(const general_span_iterator& rhs) const { return rhs < *this; }
bool operator>=(const general_span_iterator& rhs) const { return !(rhs > *this); }
void swap(general_span_iterator& rhs) noexcept
{
std::swap(m_itr, rhs.m_itr);
std::swap(m_container, rhs.m_container);
}
2015-08-20 21:09:14 -04:00
};
template <typename Span>
2015-11-24 15:49:03 -05:00
general_span_iterator<Span> operator+(typename general_span_iterator<Span>::difference_type n,
const general_span_iterator<Span>& rhs) noexcept
2015-08-20 21:09:14 -04:00
{
return rhs + n;
2015-08-20 21:09:14 -04:00
}
} // namespace gsl
2015-08-20 21:09:14 -04:00
Clang cl (#762) * Added c++17 test configurations for clang5.0 and clang6.0 * Fix #739 correct cppcorecheck warnings for clang-cl * Add clang-cl configurations * Corrections Appveyor; Temporarily disable msvc compilation for faster testing (#741) * Add path to clang-cl.exe (#741) * Escape backslash in path (#741) * Update vcpkg (#741) * Check vcpkg version; try without building vcpkg; use latest clang-cl from path (#741) * Fix blocks in ps script (#741) * Try accessing APPVEYOR_BUILD_FOLDER variable (#471) * Update span size() bug confirmation test for GCC 6.5 (#741) * MSVC flags to Clang-cl; disable c++98-compat and undefined macro warnings (#741) * Suppress clang warning on tests (missing-prototypes) (#741) * Fix clang warning -Wnewline-eof (#741) * Fix clang warning -Wdouble-promotion (#741) * Set linker explicitly * Clean condition statement * For Clang, fallback to the AppVeyor installed version of CMake * Fix clang warning -Wmissing-variable-declarations * Fallback to the MSVC linker until vcpkg has been updated * Revert "Fallback to the MSVC linker until vcpkg has been updated" This reverts commit 7263f3289e6e835c32fc7800d0c2d4e58bd21178. * Fix clang warning -Wunused-member-function * Fix clang warning -Wmissing-noreturn * Fix clang warning -Winvalid-noreturn on Windows * Add macro block end comment on large #if blocks * Workaround: fallback to mscv link.exe * Workaround: get msvc paths into PowerShell through intermediate file * Workaround: fix, remove "PATH=" from text * Workaround: try with full-path; and return user PATH * Workaround: fix, escape backslashes * Revert all since "Workaround: fallback to mscv link.exe" did not work on AppVeyor This reverts the commits: bda3d6a428e5d19e97375b2e575b0f51ff1b4bc0 97062933acfb6428535c0fdcab5d94371ce72bfc 0f4fb04bac9c2d091005b791294237250dbe0668 1b0c19afd154f4ffc5ef793014c1bc2324534fd0 a5739ea5f0cd7633527b5e5d3b16a9e3ade7149f * Suppress output of git pull; remove vcpkg from cache * Re-enable AppVeyor builds for all platforms * Correct typo Co-Authored-By: Farwaykorse <Farwaykorse@users.noreply.github.com> * Add Clang-cl 7.0.0 to the supported platforms * Revert "Fix clang warning -Wunused-member-function" This reverts commit 6fe1a4203501145ab4350b9152ecc11f3a30e49a. * Fix or locally suppress clang warning -Wunused-member-function * format touched code and correct comment * git pull --quiet * fix logic error in workaround * fix missing bracket * Suppress output of mkdir * Replace MSBuild with Ninja * Suppress output of 7z * Add architecture flags for Clang * Drop workaround for lld-link * 7-zip Overwrite and Alternative output suppression without suppressing errors Replaces 3c1c0794dd9a29908cc7c38f591bd3c7b4929677 * AppVeyor setup and CMake before build * reorder compiler configuration * remove unnecessary * remove -fno-strict-aliasing * remove -Wsign-conversion, since before v4.0 part of -Wconversion * -Wctor-dtor-privacy is GCC only * remove -Woverloaded-virtual part of -Wmost, part of -Wall * add -Wmissing-noreturn * remove the pragmas for -Wunused-member-function * Re-add MSBuild generator on AppVeyor * Print CMake commands * Add MSBuild toolset selection * Separate Architecture setting * clang-cl: add -Weverything * clang-cl -Wno-c++98-compat * clang-cl -Wno-c++98-compat-pedantic * clang-cl -Wno-missing-prototypes * clang-cl C++14 -Wno-unused-member-function * clang-cl -Wundef __GNUC__ * clang++: add -Weverything * clang++ -Wno-c++98-compat * clang++ -Wno-c++98-compat-pedantic * clang++ -Wno-missing-prototypes * clang++ -Wno-weak-vtables * clang++ C++14 -Wno-unused-member-function * clang++ fix -Wundef _MSC_VER * clang++ -Wno-padded * clang++ solve -Wdeprecated * Add AppleClang compiler target Since CMake v3.0 use of Clang for both is deprecated * clang++ v5.0 C++17 -Wno-undefined-func-template * Add VS2015 + LLVM/clang-cl to AppVeyor * Do not disable constexpr when compiling with clang-cl on Windows * Clean-up clang-only warnings (now under -Weverything) * Revert "Fix clang warning -Winvalid-noreturn on Windows" This reverts commit 2238c4760e86feebb2a18620b77312bd01055f61. * Suppress -Winvalid-noreturn for the MS STL noexception workaround * CMake: put preprocessor definition in target_compile_definitions * Solve compiler warning C4668: __GNUC__ not defined
2019-01-15 13:27:34 -05:00
#if defined(_MSC_VER) && !defined(__clang__)
#if _MSC_VER < 1910
#undef constexpr
#pragma pop_macro("constexpr")
#endif // _MSC_VER < 1910
2015-11-17 18:07:51 -05:00
#pragma warning(pop)
2017-07-14 07:40:27 -04:00
#endif // _MSC_VER
2015-09-24 21:08:34 -04:00
Clang cl (#762) * Added c++17 test configurations for clang5.0 and clang6.0 * Fix #739 correct cppcorecheck warnings for clang-cl * Add clang-cl configurations * Corrections Appveyor; Temporarily disable msvc compilation for faster testing (#741) * Add path to clang-cl.exe (#741) * Escape backslash in path (#741) * Update vcpkg (#741) * Check vcpkg version; try without building vcpkg; use latest clang-cl from path (#741) * Fix blocks in ps script (#741) * Try accessing APPVEYOR_BUILD_FOLDER variable (#471) * Update span size() bug confirmation test for GCC 6.5 (#741) * MSVC flags to Clang-cl; disable c++98-compat and undefined macro warnings (#741) * Suppress clang warning on tests (missing-prototypes) (#741) * Fix clang warning -Wnewline-eof (#741) * Fix clang warning -Wdouble-promotion (#741) * Set linker explicitly * Clean condition statement * For Clang, fallback to the AppVeyor installed version of CMake * Fix clang warning -Wmissing-variable-declarations * Fallback to the MSVC linker until vcpkg has been updated * Revert "Fallback to the MSVC linker until vcpkg has been updated" This reverts commit 7263f3289e6e835c32fc7800d0c2d4e58bd21178. * Fix clang warning -Wunused-member-function * Fix clang warning -Wmissing-noreturn * Fix clang warning -Winvalid-noreturn on Windows * Add macro block end comment on large #if blocks * Workaround: fallback to mscv link.exe * Workaround: get msvc paths into PowerShell through intermediate file * Workaround: fix, remove "PATH=" from text * Workaround: try with full-path; and return user PATH * Workaround: fix, escape backslashes * Revert all since "Workaround: fallback to mscv link.exe" did not work on AppVeyor This reverts the commits: bda3d6a428e5d19e97375b2e575b0f51ff1b4bc0 97062933acfb6428535c0fdcab5d94371ce72bfc 0f4fb04bac9c2d091005b791294237250dbe0668 1b0c19afd154f4ffc5ef793014c1bc2324534fd0 a5739ea5f0cd7633527b5e5d3b16a9e3ade7149f * Suppress output of git pull; remove vcpkg from cache * Re-enable AppVeyor builds for all platforms * Correct typo Co-Authored-By: Farwaykorse <Farwaykorse@users.noreply.github.com> * Add Clang-cl 7.0.0 to the supported platforms * Revert "Fix clang warning -Wunused-member-function" This reverts commit 6fe1a4203501145ab4350b9152ecc11f3a30e49a. * Fix or locally suppress clang warning -Wunused-member-function * format touched code and correct comment * git pull --quiet * fix logic error in workaround * fix missing bracket * Suppress output of mkdir * Replace MSBuild with Ninja * Suppress output of 7z * Add architecture flags for Clang * Drop workaround for lld-link * 7-zip Overwrite and Alternative output suppression without suppressing errors Replaces 3c1c0794dd9a29908cc7c38f591bd3c7b4929677 * AppVeyor setup and CMake before build * reorder compiler configuration * remove unnecessary * remove -fno-strict-aliasing * remove -Wsign-conversion, since before v4.0 part of -Wconversion * -Wctor-dtor-privacy is GCC only * remove -Woverloaded-virtual part of -Wmost, part of -Wall * add -Wmissing-noreturn * remove the pragmas for -Wunused-member-function * Re-add MSBuild generator on AppVeyor * Print CMake commands * Add MSBuild toolset selection * Separate Architecture setting * clang-cl: add -Weverything * clang-cl -Wno-c++98-compat * clang-cl -Wno-c++98-compat-pedantic * clang-cl -Wno-missing-prototypes * clang-cl C++14 -Wno-unused-member-function * clang-cl -Wundef __GNUC__ * clang++: add -Weverything * clang++ -Wno-c++98-compat * clang++ -Wno-c++98-compat-pedantic * clang++ -Wno-missing-prototypes * clang++ -Wno-weak-vtables * clang++ C++14 -Wno-unused-member-function * clang++ fix -Wundef _MSC_VER * clang++ -Wno-padded * clang++ solve -Wdeprecated * Add AppleClang compiler target Since CMake v3.0 use of Clang for both is deprecated * clang++ v5.0 C++17 -Wno-undefined-func-template * Add VS2015 + LLVM/clang-cl to AppVeyor * Do not disable constexpr when compiling with clang-cl on Windows * Clean-up clang-only warnings (now under -Weverything) * Revert "Fix clang warning -Winvalid-noreturn on Windows" This reverts commit 2238c4760e86feebb2a18620b77312bd01055f61. * Suppress -Winvalid-noreturn for the MS STL noexception workaround * CMake: put preprocessor definition in target_compile_definitions * Solve compiler warning C4668: __GNUC__ not defined
2019-01-15 13:27:34 -05:00
#if defined(__GNUC__) && __GNUC__ > 6
#pragma GCC diagnostic pop
#endif // __GNUC__ > 6
2016-02-24 14:26:28 -05:00
#endif // GSL_MULTI_SPAN_H