algorithm.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef BOOST_MULTI_ARRAY_ALGORITHM_HPP
  2. #define BOOST_MULTI_ARRAY_ALGORITHM_HPP
  3. //
  4. //
  5. // Copyright (c) 1994
  6. // Hewlett-Packard Company
  7. //
  8. // Permission to use, copy, modify, distribute and sell this software
  9. // and its documentation for any purpose is hereby granted without fee,
  10. // provided that the above copyright notice appear in all copies and
  11. // that both that copyright notice and this permission notice appear
  12. // in supporting documentation. Hewlett-Packard Company makes no
  13. // representations about the suitability of this software for any
  14. // purpose. It is provided "as is" without express or implied warranty.
  15. //
  16. //
  17. // Copyright (c) 1996-1998
  18. // Silicon Graphics Computer Systems, Inc.
  19. //
  20. // Permission to use, copy, modify, distribute and sell this software
  21. // and its documentation for any purpose is hereby granted without fee,
  22. // provided that the above copyright notice appear in all copies and
  23. // that both that copyright notice and this permission notice appear
  24. // in supporting documentation. Silicon Graphics makes no
  25. // representations about the suitability of this software for any
  26. // purpose. It is provided "as is" without express or implied warranty.
  27. //
  28. // Copyright 2002 The Trustees of Indiana University.
  29. // Use, modification and distribution is subject to the Boost Software
  30. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  31. // http://www.boost.org/LICENSE_1_0.txt)
  32. // Boost.MultiArray Library
  33. // Authors: Ronald Garcia
  34. // Jeremy Siek
  35. // Andrew Lumsdaine
  36. // See http://www.boost.org/libs/multi_array for documentation.
  37. #include <iterator>
  38. namespace boost {
  39. namespace detail {
  40. namespace multi_array {
  41. //--------------------------------------------------
  42. // copy_n (not part of the C++ standard)
  43. #if 1
  44. template <class InputIter, class Size, class OutputIter>
  45. OutputIter copy_n(InputIter first, Size count,
  46. OutputIter result) {
  47. for ( ; count > 0; --count) {
  48. *result = *first;
  49. ++first;
  50. ++result;
  51. }
  52. return result;
  53. }
  54. #else // !1
  55. template <class InputIter, class Size, class OutputIter>
  56. OutputIter copy_n__(InputIter first, Size count,
  57. OutputIter result,
  58. std::input_iterator_tag) {
  59. for ( ; count > 0; --count) {
  60. *result = *first;
  61. ++first;
  62. ++result;
  63. }
  64. return result;
  65. }
  66. template <class RAIter, class Size, class OutputIter>
  67. inline OutputIter
  68. copy_n__(RAIter first, Size count,
  69. OutputIter result,
  70. std::random_access_iterator_tag) {
  71. RAIter last = first + count;
  72. return std::copy(first, last, result);
  73. }
  74. template <class InputIter, class Size, class OutputIter>
  75. inline OutputIter
  76. copy_n__(InputIter first, Size count, OutputIter result) {
  77. typedef typename std::iterator_traits<InputIter>::iterator_category cat;
  78. return copy_n__(first, count, result, cat());
  79. }
  80. template <class InputIter, class Size, class OutputIter>
  81. inline OutputIter
  82. copy_n(InputIter first, Size count, OutputIter result) {
  83. return copy_n__(first, count, result);
  84. }
  85. #endif // 1
  86. } // namespace multi_array
  87. } // namespace detail
  88. } // namespace boost
  89. #endif