Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:16

0001 ///////////////////////////////////////////////////////////////
0002 //  Copyright 2019 John Maddock. Distributed under the Boost
0003 //  Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
0005 
0006 #ifndef BOOST_MP_DETAIL_CONSTEXPR_HPP
0007 #define BOOST_MP_DETAIL_CONSTEXPR_HPP
0008 
0009 #include <cstring>
0010 #include <boost/multiprecision/detail/standalone_config.hpp>
0011 
0012 namespace boost {
0013 
0014 namespace multiprecision {
0015 
0016 namespace std_constexpr {
0017 
0018 template <class T>
0019 inline BOOST_CXX14_CONSTEXPR void swap(T& a, T& b)
0020 {
0021    T t(a);
0022    a = b;
0023    b = t;
0024 }
0025 
0026 template <class InputIterator, class OutputIterator>
0027 inline BOOST_CXX14_CONSTEXPR OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result)
0028 {
0029    //
0030    // There are 3 branches here, only one of which is selected at compile time:
0031    //
0032 #ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
0033    if (BOOST_MP_IS_CONST_EVALUATED(*first))
0034    {
0035       // constexpr safe code, never generates runtime code:
0036       while (first != last)
0037       {
0038          *result = *first;
0039          ++first;
0040          ++result;
0041       }
0042       return result;
0043    }
0044    else
0045 #endif
0046    {
0047 #ifndef BOOST_NO_CXX17_IF_CONSTEXPR
0048       if constexpr (std::is_pointer<InputIterator>::value && std::is_pointer<OutputIterator>::value && std::is_trivially_copyable<typename std::remove_reference<decltype(*first)>::type>::value)
0049       {
0050          // The normal runtime branch:
0051          std::memcpy(result, first, static_cast<std::size_t>(static_cast<std::size_t>(last - first) * sizeof(*first)));
0052          return result + (last - first);
0053       }
0054       else
0055 #endif
0056       {
0057          // Alternate runtime branch:
0058          while (first != last)
0059          {
0060             *result = *first;
0061             ++first;
0062             ++result;
0063          }
0064          return result;
0065       }
0066    }
0067 }
0068 
0069 template <class I>
0070 inline BOOST_CXX14_CONSTEXPR bool equal(const I* first, const I* last, const I* other)
0071 {
0072    while (first != last)
0073    {
0074       if (*first != *other)
0075          return false;
0076       ++first;
0077       ++other;
0078    }
0079    return true;
0080 }
0081 
0082 }
0083 
0084 }
0085 
0086 } // namespace boost::multiprecision::std_constexpr
0087 
0088 #endif