Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/gsl/algorithm is written in an unsupported language. File is not indexed.

0001 ///////////////////////////////////////////////////////////////////////////////
0002 //
0003 // Copyright (c) 2015 Microsoft Corporation. All rights reserved.
0004 //
0005 // This code is licensed under the MIT License (MIT).
0006 //
0007 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0008 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0009 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0010 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0011 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0012 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0013 // THE SOFTWARE.
0014 //
0015 ///////////////////////////////////////////////////////////////////////////////
0016 
0017 #ifndef GSL_ALGORITHM_H
0018 #define GSL_ALGORITHM_H
0019 
0020 #include <gsl/assert> // for Expects
0021 #include <gsl/span>   // for dynamic_extent, span
0022 
0023 #include <algorithm>   // for copy_n
0024 #include <cstddef>     // for ptrdiff_t
0025 #include <type_traits> // for is_assignable
0026 
0027 #ifdef _MSC_VER
0028 #pragma warning(push)
0029 
0030 // turn off some warnings that are noisy about our Expects statements
0031 #pragma warning(disable : 4127) // conditional expression is constant
0032 #pragma warning(disable : 4996) // unsafe use of std::copy_n
0033 
0034 #endif // _MSC_VER
0035 
0036 namespace gsl
0037 {
0038 // Note: this will generate faster code than std::copy using span iterator in older msvc+stl
0039 // not necessary for msvc since VS2017 15.8 (_MSC_VER >= 1915)
0040 template <class SrcElementType, std::size_t SrcExtent, class DestElementType,
0041           std::size_t DestExtent>
0042 void copy(span<SrcElementType, SrcExtent> src, span<DestElementType, DestExtent> dest)
0043 {
0044     static_assert(std::is_assignable<decltype(*dest.data()), decltype(*src.data())>::value,
0045                   "Elements of source span can not be assigned to elements of destination span");
0046     static_assert(SrcExtent == dynamic_extent || DestExtent == dynamic_extent ||
0047                       (SrcExtent <= DestExtent),
0048                   "Source range is longer than target range");
0049 
0050     Expects(dest.size() >= src.size());
0051     // clang-format off
0052     GSL_SUPPRESS(stl.1) // NO-FORMAT: attribute
0053     // clang-format on
0054     std::copy_n(src.data(), src.size(), dest.data());
0055 }
0056 
0057 } // namespace gsl
0058 
0059 #ifdef _MSC_VER
0060 #pragma warning(pop)
0061 #endif // _MSC_VER
0062 
0063 #endif // GSL_ALGORITHM_H