From ef85dcaebb2463fead009f7e4801e67950e88fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Fri, 10 Jun 2011 13:26:42 +0000 Subject: [PATCH] Added a test for copy_n and fixed a bug where you would only end up with a linker error instead of a "no such definition" error when CGAL_NO_DEPRECATED_CODE was used --- STL_Extension/include/CGAL/algorithm.h | 54 ++++++++++--------- .../test/STL_Extension/test_stl_extension.cpp | 11 ++++ 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/STL_Extension/include/CGAL/algorithm.h b/STL_Extension/include/CGAL/algorithm.h index 0f2511fd7ec..d7d9d3f2e88 100644 --- a/STL_Extension/include/CGAL/algorithm.h +++ b/STL_Extension/include/CGAL/algorithm.h @@ -27,6 +27,7 @@ #define CGAL_ALGORITHM_H #include +#include #include #include @@ -34,32 +35,13 @@ namespace CGAL { // copy_n is usually in the STL as well, but not in the official // standard. We provide our own copy_n. It is planned for C++0x. -// Our own version will be marked deprecated if C++0x is -// available. +// Our own version is declared deprecated, if std::copy_n is +// available. If std::copy_n is available + +#ifndef CGAL_CFG_NO_CPP0X_COPY_N #ifndef CGAL_NO_DEPRECATED_CODE -#ifndef CGAL_CFG_NO_CPP0X_COPY_N - template -CGAL_DEPRECATED OutputIterator copy_n( InputIterator, Size, OutputIterator); - -#endif //CGAL_CFG_NOCPP0X_COPY_N -#endif //CGAL_NO_DEPRECATED_CODE - -namespace cpp0x { -#ifndef CGAL_CFG_NO_CPP0X_COPY_N - using std::copy_n; -#else - using CGAL::copy_n; -#endif -} // cpp0x - -#ifndef CGAL_NO_DEPRECATED_CODE -#ifndef CGAL_CFG_NO_CPP0X_COPY_N - -template -OutputIterator copy_n( InputIterator first, - Size n, - OutputIterator result) +CGAL_DEPRECATED OutputIterator copy_n( InputIterator first, Size n, OutputIterator result ) { // copies the first `n' items from `first' to `result'. Returns // the value of `result' after inserting the `n' items. @@ -70,9 +52,29 @@ OutputIterator copy_n( InputIterator first, } return result; } +#endif // CGAL_NO_DEPRECATED_CODE +#else +template +OutputIterator copy_n( InputIterator first, Size n, OutputIterator result ) +{ + // copies the first `n' items from `first' to `result'. Returns + // the value of `result' after inserting the `n' items. + while( n--) { + *result = *first; + first++; + result++; + } + return result; +} +#endif // CGAL_CFG_NO_CPP0X_COPY_N -#endif //CGAL_CFG_NOCPP0X_COPY_N -#endif //CGAL_NO_DEPRECATED_CODE +namespace cpp0x { +#ifndef CGAL_CFG_NO_CPP0X_COPY_N + using std::copy_n; +#else + using CGAL::copy_n; +#endif +} // cpp0x // Not documented template inline diff --git a/STL_Extension/test/STL_Extension/test_stl_extension.cpp b/STL_Extension/test/STL_Extension/test_stl_extension.cpp index e4fd55710f4..1e635007171 100644 --- a/STL_Extension/test/STL_Extension/test_stl_extension.cpp +++ b/STL_Extension/test/STL_Extension/test_stl_extension.cpp @@ -9016,6 +9016,16 @@ void test_predecessor_successor() CGAL_assertion(successor(successor(V.begin())) == predecessor(V.end())); } +void test_copy_n() { + std::vector V; + for(int i = 0; i < 10; ++i) + V.push_back(i); + + std::vector V2(5); + cpp0x::copy_n(V.begin(), 5, V2.begin()); + + CGAL_assertion(std::equal(V2.begin(), V2.end(), V.begin())); +} int main() { init_global_data(); @@ -9038,6 +9048,7 @@ int main() { test_predecessor_successor(); clean_global_data(); test_tuple(); + test_copy_n(); return 0; } // EOF //