/////////////////////////////////////////////////////////////////////////////// // // 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. // /////////////////////////////////////////////////////////////////////////////// #ifndef GSL_SPAN_EXT_H #define GSL_SPAN_EXT_H /////////////////////////////////////////////////////////////////////////////// // // File: span_ext // Purpose: continue offering features that have been cut from the official // implementation of span. // While modernizing gsl::span a number of features needed to be removed to // be compliant with the design of std::span // /////////////////////////////////////////////////////////////////////////////// #include // for span #include // for narrow_cast, narrow #include // for lexicographical_compare #include // for ptrdiff_t, size_t #include namespace gsl { // [span.comparison], span comparison operators template constexpr bool operator==(span l, span r) { return std::equal(l.begin(), l.end(), r.begin(), r.end()); } template constexpr bool operator!=(span l, span r) { return !(l == r); } template constexpr bool operator<(span l, span r) { return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end()); } template constexpr bool operator<=(span l, span r) { return !(l > r); } template constexpr bool operator>(span l, span r) { return r < l; } template constexpr bool operator>=(span l, span r) { return !(l < r); } // // make_span() - Utility functions for creating spans // template constexpr span make_span(ElementType* ptr, typename span::size_type count) { return span(ptr, count); } template constexpr span make_span(ElementType* firstElem, ElementType* lastElem) { return span(firstElem, lastElem); } template constexpr span make_span(ElementType (&arr)[N]) noexcept { return span(arr); } template constexpr span make_span(Container& cont) { return span(cont); } template constexpr span make_span(const Container& cont) { return span(cont); } template constexpr span make_span(Ptr& cont, std::size_t count) { return span(cont, count); } template constexpr span make_span(Ptr& cont) { return span(cont); } // Specialization of gsl::at for span template constexpr ElementType& at(span s, index i) { // No bounds checking here because it is done in span::operator[] called below Ensures(i >= 0); return s[narrow_cast(i)]; } // [span.obs] Free observer functions template constexpr std::ptrdiff_t ssize(const span& s) noexcept { return static_cast(s.size()); } // [span.iter] Free functions for begin/end functions template constexpr typename span::iterator begin(const span& s) noexcept { return s.begin(); } template constexpr typename span::iterator end(const span& s) noexcept { return s.end(); } template constexpr typename span::reverse_iterator rbegin(const span& s) noexcept { return s.rbegin(); } template constexpr typename span::reverse_iterator rend(const span& s) noexcept { return s.rend(); } template constexpr typename span::iterator cbegin(const span& s) noexcept { return s.begin(); } template constexpr typename span::iterator cend(const span& s) noexcept { return s.end(); } template constexpr typename span::reverse_iterator crbegin(const span& s) noexcept { return s.rbegin(); } template constexpr typename span::reverse_iterator crend(const span& s) noexcept { return s.rend(); } } // namespace gsl #endif // GSL_SPAN_EXT_H