1/////////////////////////////////////////////////////////////////////////////// 2// 3// Copyright (c) 2015 Microsoft Corporation. All rights reserved. 4// 5// This code is licensed under the MIT License (MIT). 6// 7// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 8// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 9// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 10// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 11// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 12// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 13// THE SOFTWARE. 14// 15/////////////////////////////////////////////////////////////////////////////// 16 17#pragma once 18 19#ifndef GSL_ALGORITHM_H 20#define GSL_ALGORITHM_H 21 22#include <gsl/span> 23 24#include <algorithm> 25 26#ifdef _MSC_VER 27#pragma warning(push) 28 29// turn off some warnings that are noisy about our Expects statements 30#pragma warning(disable : 4127) // conditional expression is constant 31 32// blanket turn off warnings from CppCoreCheck for now 33// so people aren't annoyed by them when running the tool. 34// more targeted suppressions will be added in a future update to the GSL 35#pragma warning(disable : 26481 26482 26483 26485 26490 26491 26492 26493 26495) 36#endif // _MSC_VER 37 38namespace gsl 39{ 40 41template <class SrcElementType, std::ptrdiff_t SrcExtent, class DestElementType, 42 std::ptrdiff_t DestExtent> 43void copy(span<SrcElementType, SrcExtent> src, span<DestElementType, DestExtent> dest) 44{ 45 static_assert(std::is_assignable<decltype(*dest.data()), decltype(*src.data())>::value, 46 "Elements of source span can not be assigned to elements of destination span"); 47 static_assert(SrcExtent == dynamic_extent || DestExtent == dynamic_extent || 48 (SrcExtent <= DestExtent), 49 "Source range is longer than target range"); 50 51 Expects(dest.size() >= src.size()); 52 std::copy_n(src.data(), src.size(), dest.data()); 53} 54 55} // namespace gsl 56 57#ifdef _MSC_VER 58#pragma warning(pop) 59#endif // _MSC_VER 60 61#endif // GSL_ALGORITHM_H 62