You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
5.3 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/algorithms/debug.hpp
  3. *
  4. * Purpose: Debug algorithms.
  5. *
  6. * Created: 17th January 2002
  7. * Updated: 26th March 2010
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2002-2010, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////////// */
  39. /** \file stlsoft/algorithms/debug.hpp
  40. *
  41. * \brief [C++ only] Debug algorithms
  42. * (\ref group__library__algorithms "Algorithms" Library).
  43. */
  44. #ifndef STLSOFT_INCL_STLSOFT_ALGORITHMS_HPP_DEBUG
  45. #define STLSOFT_INCL_STLSOFT_ALGORITHMS_HPP_DEBUG
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define STLSOFT_VER_STLSOFT_ALGORITHMS_HPP_DEBUG_MAJOR 3
  48. # define STLSOFT_VER_STLSOFT_ALGORITHMS_HPP_DEBUG_MINOR 1
  49. # define STLSOFT_VER_STLSOFT_ALGORITHMS_HPP_DEBUG_REVISION 1
  50. # define STLSOFT_VER_STLSOFT_ALGORITHMS_HPP_DEBUG_EDIT 68
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Compatibility
  54. */
  55. /* /////////////////////////////////////////////////////////////////////////
  56. * Includes
  57. */
  58. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  59. # include <stlsoft/stlsoft.h>
  60. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Namespace
  63. */
  64. #ifndef _STLSOFT_NO_NAMESPACE
  65. namespace stlsoft
  66. {
  67. #endif /* _STLSOFT_NO_NAMESPACE */
  68. /* /////////////////////////////////////////////////////////////////////////
  69. * Algorithms
  70. */
  71. template< ss_typename_param_k I
  72. , ss_typename_param_k O
  73. >
  74. // [[synesis:function:algorithm: copy_preinc(T<I> first, T<I> last, T<O> o)]]
  75. inline O copy_preinc(
  76. I first
  77. , I last
  78. , O o
  79. )
  80. {
  81. for(; first != last; ++o, ++first)
  82. {
  83. *o = *first;
  84. }
  85. return o;
  86. }
  87. // [[synesis:function:algorithm: copy_postinc(T<I> first, T<I> last, T<O> o)]]
  88. template< ss_typename_param_k I
  89. , ss_typename_param_k O
  90. >
  91. inline O copy_postinc(
  92. I first
  93. , I last
  94. , O o
  95. )
  96. {
  97. for(; first != last; o++, first++)
  98. {
  99. *o = *first;
  100. }
  101. return o;
  102. }
  103. /** \brief Carries out for_each on the range, using pre-increment on the iterator
  104. *
  105. * \ingroup group__library__algorithms
  106. *
  107. * \param first The start of the sequence
  108. * \param last The end of the sequence
  109. * \param func The function
  110. */
  111. // [[synesis:function:algorithm: for_each_preinc(T<I> first, T<I> last, T<UF> func)]]
  112. template< ss_typename_param_k I
  113. , ss_typename_param_k UF
  114. >
  115. inline UF for_each_preinc(I first, I last, UF func)
  116. {
  117. for(; first != last; ++first)
  118. {
  119. func(*first);
  120. }
  121. return func;
  122. }
  123. /** \brief Carries out for_each on the range, using post-increment on the iterator
  124. *
  125. * \ingroup group__library__algorithms
  126. *
  127. * \param first The start of the sequence
  128. * \param last The end of the sequence
  129. * \param func The function
  130. */
  131. // [[synesis:function:algorithm: for_each_postinc(T<I> first, T<I> last, T<UF> func)]]
  132. template< ss_typename_param_k I
  133. , ss_typename_param_k UF
  134. >
  135. inline UF for_each_postinc(I first, I last, UF func)
  136. {
  137. for(; first != last; first++)
  138. {
  139. func(*first);
  140. }
  141. return func;
  142. }
  143. ////////////////////////////////////////////////////////////////////////////
  144. // Unit-testing
  145. #ifdef STLSOFT_UNITTEST
  146. # include "./unittest/debug_unittest_.h"
  147. #endif /* STLSOFT_UNITTEST */
  148. /* ////////////////////////////////////////////////////////////////////// */
  149. #ifndef _STLSOFT_NO_NAMESPACE
  150. } // namespace stlsoft
  151. #endif /* _STLSOFT_NO_NAMESPACE */
  152. /* ////////////////////////////////////////////////////////////////////// */
  153. #endif /* !STLSOFT_INCL_STLSOFT_ALGORITHMS_HPP_DEBUG */
  154. /* ///////////////////////////// end of file //////////////////////////// */