BVB Source Codes

mars Show partition_copy.hpp Source code

Return Download mars: download partition_copy.hpp Source code - Download mars Source code - Type:.hpp
  1. /*
  2.    Copyright (c) Marshall Clow 2011-2012.
  3.  
  4.    Distributed under the Boost Software License, Version 1.0. (See accompanying
  5.    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7.  
  8. /// \file  partition_copy.hpp
  9. /// \brief Copy a subset of a sequence to a new sequence
  10. /// \author Marshall Clow
  11.  
  12. #ifndef BOOST_ALGORITHM_PARTITION_COPY_HPP
  13. #define BOOST_ALGORITHM_PARTITION_COPY_HPP
  14.  
  15. #include <algorithm>    // for std::partition_copy, if available
  16. #include <utility>  // for make_pair
  17.  
  18. #include <boost/range/begin.hpp>
  19. #include <boost/range/end.hpp>
  20.  
  21. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {  namespace algorithm {
  22.  
  23. #if __cplusplus >= 201103L
  24. //  Use the C++11 versions of partition_copy if it is available
  25. using std::partition_copy;  // Section 25.3.13
  26. #else
  27. /// \fn partition_copy ( InputIterator first, InputIterator last,
  28. ///     OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p )
  29. /// \brief Copies the elements that satisfy the predicate p from the range [first, last)
  30. ///     to the range beginning at d_first_true, and
  31. ///     copies the elements that do not satisfy p to the range beginning at d_first_false.
  32. ///
  33. ///
  34. /// \param first     The start of the input sequence
  35. /// \param last      One past the end of the input sequence
  36. /// \param out_true  An output iterator to write the elements that satisfy the predicate into
  37. /// \param out_false An output iterator to write the elements that do not satisfy the predicate into
  38. /// \param p         A predicate for dividing the elements of the input sequence.
  39. ///
  40. /// \note            This function is part of the C++2011 standard library.
  41. ///  We will use the standard one if it is available,
  42. ///  otherwise we have our own implementation.
  43. template <typename InputIterator,
  44.         typename OutputIterator1, typename OutputIterator2, typename UnaryPredicate>
  45. std::pair<OutputIterator1, OutputIterator2>
  46. partition_copy ( InputIterator first, InputIterator last,
  47.         OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p )
  48. {
  49.     for ( ; first != last; ++first )
  50.         if ( p (*first))
  51.             *out_true++ = *first;
  52.         else
  53.             *out_false++ = *first;
  54.     return std::pair<OutputIterator1, OutputIterator2> ( out_true, out_false );
  55. }
  56. #endif
  57.  
  58. /// \fn partition_copy ( const Range &r,
  59. ///     OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p )
  60. ///
  61. /// \param r         The input range
  62. /// \param out_true  An output iterator to write the elements that satisfy the predicate into
  63. /// \param out_false An output iterator to write the elements that do not satisfy the predicate into
  64. /// \param p         A predicate for dividing the elements of the input sequence.
  65. ///
  66. template <typename Range, typename OutputIterator1, typename OutputIterator2,
  67.             typename UnaryPredicate>
  68. std::pair<OutputIterator1, OutputIterator2>
  69. partition_copy ( const Range &r, OutputIterator1 out_true, OutputIterator2 out_false,
  70.                                 UnaryPredicate p )
  71. {
  72.     return mars_boost::algorithm::partition_copy
  73.                       (mars_boost::begin(r), mars_boost::end(r), out_true, out_false, p );
  74. }
  75.  
  76. }} // namespace boost and algorithm
  77.  
  78. #endif  // BOOST_ALGORITHM_PARTITION_COPY_HPP
  79.  
downloadpartition_copy.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