BVB Source Codes

mars Show swap.hpp Source code

Return Download mars: download swap.hpp Source code - Download mars Source code - Type:.hpp
  1. // Copyright (C) 2007, 2008 Steven Watanabe, Joseph Gauterin, Niels Dekker
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // For more information, see http://www.boost.org
  7.  
  8.  
  9. #ifndef BOOST_CORE_SWAP_HPP
  10. #define BOOST_CORE_SWAP_HPP
  11.  
  12. // Note: the implementation of this utility contains various workarounds:
  13. // - swap_impl is put outside the boost namespace, to avoid infinite
  14. // recursion (causing stack overflow) when swapping objects of a primitive
  15. // type.
  16. // - swap_impl has a using-directive, rather than a using-declaration,
  17. // because some compilers (including MSVC 7.1, Borland 5.9.3, and
  18. // Intel 8.1) don't do argument-dependent lookup when it has a
  19. // using-declaration instead.
  20. // - mars_boost::swap has two template arguments, instead of one, to
  21. // avoid ambiguity when swapping objects of a Boost type that does
  22. // not have its own mars_boost::swap overload.
  23.  
  24. #include <utility> //for std::swap (C++11)
  25. #include <algorithm> //for std::swap (C++98)
  26. #include <cstddef> //for std::size_t
  27. #include <boost/config.hpp>
  28.  
  29. namespace mars_boost_swap_impl
  30. {
  31.   template<class T>
  32.   BOOST_GPU_ENABLED
  33.   void swap_impl(T& left, T& right)
  34.   {
  35.     using namespace std;//use std::swap if argument dependent lookup fails
  36.     swap(left,right);
  37.   }
  38.  
  39.   template<class T, std::size_t N>
  40.   BOOST_GPU_ENABLED
  41.   void swap_impl(T (& left)[N], T (& right)[N])
  42.   {
  43.     for (std::size_t i = 0; i < N; ++i)
  44.     {
  45.       ::mars_boost_swap_impl::swap_impl(left[i], right[i]);
  46.     }
  47.   }
  48. }
  49.  
  50. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost
  51. {
  52.   template<class T1, class T2>
  53.   BOOST_GPU_ENABLED
  54.   void swap(T1& left, T2& right)
  55.   {
  56.     ::mars_boost_swap_impl::swap_impl(left, right);
  57.   }
  58. }
  59.  
  60. #endif
  61.  
downloadswap.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top