BVB Source Codes

mars Show copy_if.hpp Source code

Return Download mars: download copy_if.hpp Source code - Download mars Source code - Type:.hpp
  1. /*
  2.    Copyright (c) Marshall Clow 2008-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  copy_if.hpp
  9. /// \brief Copy a subset of a sequence to a new sequence
  10. /// \author Marshall Clow
  11.  
  12. #ifndef BOOST_ALGORITHM_COPY_IF_HPP
  13. #define BOOST_ALGORITHM_COPY_IF_HPP
  14.  
  15. #include <algorithm>    // for std::copy_if, if available
  16. #include <boost/range/begin.hpp>
  17. #include <boost/range/end.hpp>
  18.  
  19. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {  namespace algorithm {
  20.  
  21. #if __cplusplus >= 201103L && TARGET_OS_IPHONE
  22. //  Use the C++11 versions of copy_if if it is available
  23. using std::copy_if;         // Section 25.3.1
  24. #else
  25. /// \fn copy_if ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
  26. /// \brief Copies all the elements from the input range that satisfy the
  27. /// predicate to the output range.
  28. /// \return The updated output iterator
  29. ///
  30. /// \param first    The start of the input sequence
  31. /// \param last     One past the end of the input sequence
  32. /// \param result   An output iterator to write the results into
  33. /// \param p        A predicate for testing the elements of the range
  34. /// \note           This function is part of the C++2011 standard library.
  35. ///  We will use the standard one if it is available,
  36. ///  otherwise we have our own implementation.
  37. template<typename InputIterator, typename OutputIterator, typename Predicate>
  38. OutputIterator copy_if ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
  39. {
  40.     for ( ; first != last; ++first )
  41.         if (p(*first))
  42.             *result++ = *first;
  43.     return result;
  44. }
  45. #endif
  46.  
  47. /// \fn copy_if ( const Range &r, OutputIterator result, Predicate p )
  48. /// \brief Copies all the elements from the input range that satisfy the
  49. /// predicate to the output range.
  50. /// \return The updated output iterator
  51. ///
  52. /// \param r        The input range
  53. /// \param result   An output iterator to write the results into
  54. /// \param p        A predicate for testing the elements of the range
  55. ///
  56. template<typename Range, typename OutputIterator, typename Predicate>
  57. OutputIterator copy_if ( const Range &r, OutputIterator result, Predicate p )
  58. {
  59.     return mars_boost::algorithm::copy_if (mars_boost::begin (r), mars_boost::end(r), result, p);
  60. }
  61.  
  62.  
  63. /// \fn copy_while ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
  64. /// \brief Copies all the elements at the start of the input range that
  65. ///     satisfy the predicate to the output range.
  66. /// \return The updated input and output iterators
  67. ///
  68. /// \param first    The start of the input sequence
  69. /// \param last     One past the end of the input sequence
  70. /// \param result   An output iterator to write the results into
  71. /// \param p        A predicate for testing the elements of the range
  72. ///
  73. template<typename InputIterator, typename OutputIterator, typename Predicate>
  74. std::pair<InputIterator, OutputIterator>
  75. copy_while ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
  76. {
  77.     for ( ; first != last && p(*first); ++first )
  78.         *result++ = *first;
  79.     return std::make_pair(first, result);
  80. }
  81.  
  82. /// \fn copy_while ( const Range &r, OutputIterator result, Predicate p )
  83. /// \brief Copies all the elements at the start of the input range that
  84. ///     satisfy the predicate to the output range.
  85. /// \return The updated input and output iterators
  86. ///
  87. /// \param r        The input range
  88. /// \param result   An output iterator to write the results into
  89. /// \param p        A predicate for testing the elements of the range
  90. ///
  91. template<typename Range, typename OutputIterator, typename Predicate>
  92. std::pair<typename mars_boost::range_iterator<const Range>::type, OutputIterator>
  93. copy_while ( const Range &r, OutputIterator result, Predicate p )
  94. {
  95.     return mars_boost::algorithm::copy_while (mars_boost::begin (r), mars_boost::end(r), result, p);
  96. }
  97.  
  98.  
  99. /// \fn copy_until ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
  100. /// \brief Copies all the elements at the start of the input range that do not
  101. ///     satisfy the predicate to the output range.
  102. /// \return The updated output iterator
  103. ///
  104. /// \param first    The start of the input sequence
  105. /// \param last     One past the end of the input sequence
  106. /// \param result   An output iterator to write the results into
  107. /// \param p        A predicate for testing the elements of the range
  108. ///
  109. template<typename InputIterator, typename OutputIterator, typename Predicate>
  110. std::pair<InputIterator, OutputIterator>
  111. copy_until ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
  112. {
  113.     for ( ; first != last && !p(*first); ++first )
  114.         *result++ = *first;
  115.     return std::make_pair(first, result);
  116. }
  117.  
  118. /// \fn copy_until ( const Range &r, OutputIterator result, Predicate p )
  119. /// \brief Copies all the elements at the start of the input range that do not
  120. ///     satisfy the predicate to the output range.
  121. /// \return The updated output iterator
  122. ///
  123. /// \param r        The input range
  124. /// \param result   An output iterator to write the results into
  125. /// \param p        A predicate for testing the elements of the range
  126. ///
  127. template<typename Range, typename OutputIterator, typename Predicate>
  128. std::pair<typename mars_boost::range_iterator<const Range>::type, OutputIterator>
  129. copy_until ( const Range &r, OutputIterator result, Predicate p )
  130. {
  131.     return mars_boost::algorithm::copy_until (mars_boost::begin (r), mars_boost::end(r), result, p);
  132. }
  133.  
  134. }} // namespace boost and algorithm
  135.  
  136. #endif  // BOOST_ALGORITHM_COPY_IF_HPP
  137.  
downloadcopy_if.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