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
This commit is contained in:
Philipp Möller 2011-06-10 13:26:42 +00:00
parent 8eb07481ba
commit ef85dcaebb
2 changed files with 39 additions and 26 deletions

View File

@ -27,6 +27,7 @@
#define CGAL_ALGORITHM_H
#include <CGAL/basic.h>
#include <CGAL/compiler_config.h>
#include <algorithm>
#include <iosfwd>
@ -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 <class InputIterator, class Size, class OutputIterator>
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 <class InputIterator, class Size, class OutputIterator>
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 <class InputIterator, class Size, class OutputIterator>
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 <class T> inline

View File

@ -9016,6 +9016,16 @@ void test_predecessor_successor()
CGAL_assertion(successor(successor(V.begin())) == predecessor(V.end()));
}
void test_copy_n() {
std::vector<int> V;
for(int i = 0; i < 10; ++i)
V.push_back(i);
std::vector<int> 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 //