From dd7403c7651ed7b9a8e0c4233ed6c4aaf3b608fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Thu, 24 May 2012 11:23:21 +0000 Subject: [PATCH 2/4] Change the namespace to cpp11 and add an alias cpp0x. --- .gitattributes | 1 + STL_Extension/include/CGAL/algorithm.h | 13 ++++--- STL_Extension/include/CGAL/array.h | 35 ++++++++++--------- STL_Extension/include/CGAL/tuple.h | 6 ++-- .../test/STL_Extension/test_namespaces.cpp | 18 ++++++++++ 5 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 STL_Extension/test/STL_Extension/test_namespaces.cpp diff --git a/.gitattributes b/.gitattributes index f0aab4118a6..8416a5fcd20 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3490,6 +3490,7 @@ STL_Extension/include/CGAL/internal/boost/mutable_heap.hpp -text STL_Extension/include/CGAL/internal/boost/mutable_queue.hpp -text STL_Extension/test/STL_Extension/test_Modifiable_priority_queue.cpp -text STL_Extension/test/STL_Extension/test_Uncertain.cpp -text +STL_Extension/test/STL_Extension/test_namespaces.cpp -text STL_Extension/test/STL_Extension/test_type_traits.cpp -text Scripts/developer_scripts/autotest_cgal -text Scripts/developer_scripts/autotest_cgal_with_cmake -text diff --git a/STL_Extension/include/CGAL/algorithm.h b/STL_Extension/include/CGAL/algorithm.h index 3432683bec0..05f7e2cbae6 100644 --- a/STL_Extension/include/CGAL/algorithm.h +++ b/STL_Extension/include/CGAL/algorithm.h @@ -38,7 +38,7 @@ namespace CGAL { -namespace cpp0x { +namespace cpp11 { #ifndef CGAL_CFG_NO_CPP0X_NEXT_PREV using std::next; using std::prev; @@ -54,7 +54,9 @@ namespace cpp0x { return boost::prior(x, n); } #endif -} +} // namespace cpp11 + +namespace cpp0x = cpp11; // 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. @@ -91,13 +93,16 @@ OutputIterator copy_n( InputIterator first, Size n, OutputIterator result ) } #endif // CGAL_CFG_NO_CPP0X_COPY_N -namespace cpp0x { +namespace cpp11 { #ifndef CGAL_CFG_NO_CPP0X_COPY_N using std::copy_n; #else using CGAL::copy_n; #endif -} // cpp0x +} // cpp11 + +namespace cpp0x = cpp11; + // Not documented template inline diff --git a/STL_Extension/include/CGAL/array.h b/STL_Extension/include/CGAL/array.h index 7644d77c185..eee9d005fc0 100644 --- a/STL_Extension/include/CGAL/array.h +++ b/STL_Extension/include/CGAL/array.h @@ -31,7 +31,7 @@ namespace CGAL { -namespace cpp0x { +namespace cpp11 { #ifndef CGAL_CFG_NO_CPP0X_ARRAY using std::array; @@ -41,12 +41,13 @@ using std::tr1::array; using boost::array; #endif -} // cpp0x +} // cpp11 +namespace cpp0x = cpp11; // This using is just for short-term backward-compat, people should take the // habit to use CGAL::cpp0x::array. -using cpp0x::array; +using cpp11::array; // The make_array() function simply constructs an std::array. @@ -80,61 +81,61 @@ using cpp0x::array; template< typename T, typename... Args > inline -cpp0x::array< T, 1 + sizeof...(Args) > +cpp11::array< T, 1 + sizeof...(Args) > make_array(const T & t, const Args & ... args) { - cpp0x::array< T, 1 + sizeof...(Args) > a = { { t, static_cast(args)... } }; + cpp11::array< T, 1 + sizeof...(Args) > a = { { t, static_cast(args)... } }; return a; } #else // CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES template < typename T > inline -cpp0x::array +cpp11::array make_array(const T& b1) { - cpp0x::array a = { { b1 } }; + cpp11::array a = { { b1 } }; return a; } template < typename T > inline -cpp0x::array +cpp11::array make_array(const T& b1, const T& b2) { - cpp0x::array a = { { b1, b2 } }; + cpp11::array a = { { b1, b2 } }; return a; } template < typename T > inline -cpp0x::array +cpp11::array make_array(const T& b1, const T& b2, const T& b3) { - cpp0x::array a = { { b1, b2, b3 } }; + cpp11::array a = { { b1, b2, b3 } }; return a; } template < typename T > inline -cpp0x::array +cpp11::array make_array(const T& b1, const T& b2, const T& b3, const T& b4) { - cpp0x::array a = { { b1, b2, b3, b4 } }; + cpp11::array a = { { b1, b2, b3, b4 } }; return a; } template < typename T > inline -cpp0x::array +cpp11::array make_array(const T& b1, const T& b2, const T& b3, const T& b4, const T& b5) { - cpp0x::array a = { { b1, b2, b3, b4, b5 } }; + cpp11::array a = { { b1, b2, b3, b4, b5 } }; return a; } template < typename T > inline -cpp0x::array +cpp11::array make_array(const T& b1, const T& b2, const T& b3, const T& b4, const T& b5, const T& b6) { - cpp0x::array a = { { b1, b2, b3, b4, b5, b6 } }; + cpp11::array a = { { b1, b2, b3, b4, b5, b6 } }; return a; } diff --git a/STL_Extension/include/CGAL/tuple.h b/STL_Extension/include/CGAL/tuple.h index 698df419e55..d9b99013525 100644 --- a/STL_Extension/include/CGAL/tuple.h +++ b/STL_Extension/include/CGAL/tuple.h @@ -39,7 +39,7 @@ namespace CGAL { -namespace cpp0x { +namespace cpp11 { #ifndef CGAL_CFG_NO_CPP0X_TUPLE using std::tuple; @@ -112,7 +112,9 @@ get(const std::pair& pair) { #endif // end if not C++11 tuple -} // cpp0x +} // cpp11 + +namespace cpp0x = cpp11; #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES diff --git a/STL_Extension/test/STL_Extension/test_namespaces.cpp b/STL_Extension/test/STL_Extension/test_namespaces.cpp new file mode 100644 index 00000000000..dd83372a301 --- /dev/null +++ b/STL_Extension/test/STL_Extension/test_namespaces.cpp @@ -0,0 +1,18 @@ +#include +#include +#include + +int main() +{ + CGAL::cpp0x::array<3, int> arr; + CGAL::cpp11::array<3, int> arr2; + + CGAL::cpp0x::tuple tuple; + CGAL::cpp11::tuple tuple2; + + CGAL::copy_n(arr.begin(), arr.end(), arr2.begin()); + + return 0; +} + + From 9995021cdb593f83bc441f537f96996d71f91390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Thu, 24 May 2012 11:41:40 +0000 Subject: [PATCH 3/4] Changed the doc. --- STL_Extension/doc_tex/STL_Extension/main.tex | 10 ++++++++++ STL_Extension/doc_tex/STL_Extension_ref/array.tex | 4 ++-- STL_Extension/doc_tex/STL_Extension_ref/tuple.tex | 6 +++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/STL_Extension/doc_tex/STL_Extension/main.tex b/STL_Extension/doc_tex/STL_Extension/main.tex index de28c5f647f..59e2757d5ed 100644 --- a/STL_Extension/doc_tex/STL_Extension/main.tex +++ b/STL_Extension/doc_tex/STL_Extension/main.tex @@ -154,3 +154,13 @@ list. Specifying that one wishes to use the default is simply done by omitting it. This is however possible only at the end of the list. \ccc{CGAL::Default} provides a simple mechanism that performs something equivalent anywhere in the sequence. + +\section{C++ 11 wrappers} + +#Wrappers for the classes \ccc{array} and \ccc{tuple} which, based on +availability, either use the version of {\em Boost} or the one +provided by the standard library are provided in the namespace +\ccc{CGAL::cpp11}. The namespace alias \ccc{CGAL::cpp0x} is provided +for backward compatibility. Those are documented for completeness and +implementers. They are not intended to be used by users of the +library. diff --git a/STL_Extension/doc_tex/STL_Extension_ref/array.tex b/STL_Extension/doc_tex/STL_Extension_ref/array.tex index 8d6e3727c01..c202f0bb8de 100644 --- a/STL_Extension/doc_tex/STL_Extension_ref/array.tex +++ b/STL_Extension/doc_tex/STL_Extension_ref/array.tex @@ -10,14 +10,14 @@ %% +=========================================================================+ -\begin{ccRefClass}{cpp0x::array} +\begin{ccRefClass}{cpp11::array} \ccDefinition An object of the class \ccClassTemplateName\ represents an array of elements of type \ccc{T}, the number of which is specified by the second template argument. -There is actually no class in namespace \ccc{CGAL::cpp0x} with this name, but a using declaration which +There is actually no class in namespace \ccc{CGAL::cpp11} with this name, but a using declaration which imports a class from another namespace. By order of priority: the one in namespace \ccc{std} is used (provided by C++0x), if not found, then the one in namespace \ccc{std::tr1} is used (provided by TR1), and finally, the fallback solution diff --git a/STL_Extension/doc_tex/STL_Extension_ref/tuple.tex b/STL_Extension/doc_tex/STL_Extension_ref/tuple.tex index 8689874bea1..e44e31eb6d1 100644 --- a/STL_Extension/doc_tex/STL_Extension_ref/tuple.tex +++ b/STL_Extension/doc_tex/STL_Extension_ref/tuple.tex @@ -10,14 +10,14 @@ %% +=========================================================================+ -\begin{ccRefClass}{cpp0x::tuple<...>} +\begin{ccRefClass}{cpp11::tuple<...>} \ccDefinition An object of the class \ccClassTemplateName\ represents a heterogeneous tuple of elements of the types specified in parameters, which are in variadic number. -There is actually no class in namespace \ccc{CGAL::cpp0x} with this name, but a using declaration which +There is actually no class in namespace \ccc{CGAL::cpp11} with this name, but a using declaration which imports a class from another namespace. By order of priority: the one in namespace \ccc{std} is used (provided by C++0x), if not found, then the one in namespace \ccc{std::tr1} is used (provided by TR1), and finally, the fallback solution @@ -32,7 +32,7 @@ is taken from Boost. \ccHeading{Free functions and helper classes} Some free functions part of the standard interface of \ccc{tuple} are also -brought in namespace \ccc{CGAL::cpp0x} with using declarations, these are \ccc{make_tuple}, +brought in namespace \ccc{CGAL::cpp11} with using declarations, these are \ccc{make_tuple}, \ccc{get}, \ccc{tie}. Like in C++0x, the \ccc{get} function template is specialized so that it can take \ccc{std::pair} as argument. Two standard helper classes are also provided for convenience (\ccc{tuple_size} and \ccc{tuple_element}). From bb03b1753bebc6e2b5ace25d4d225366e8b6f51b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Tue, 12 Jun 2012 10:59:54 +0000 Subject: [PATCH 4/4] template arguments were the wrong way around and copy_n even compiles when used as copy when the iterators are actually pointers. --- STL_Extension/test/STL_Extension/test_namespaces.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/STL_Extension/test/STL_Extension/test_namespaces.cpp b/STL_Extension/test/STL_Extension/test_namespaces.cpp index dd83372a301..db67c195e0e 100644 --- a/STL_Extension/test/STL_Extension/test_namespaces.cpp +++ b/STL_Extension/test/STL_Extension/test_namespaces.cpp @@ -4,14 +4,18 @@ int main() { - CGAL::cpp0x::array<3, int> arr; - CGAL::cpp11::array<3, int> arr2; + CGAL::cpp0x::array arr; + CGAL::cpp11::array arr2; CGAL::cpp0x::tuple tuple; CGAL::cpp11::tuple tuple2; - CGAL::copy_n(arr.begin(), arr.end(), arr2.begin()); + CGAL::copy_n(arr.begin(), 3, arr2.begin()); + CGAL::cpp0x::prev(arr.end()); + CGAL::cpp11::prev(arr.end()); + CGAL::cpp0x::next(arr.begin()); + CGAL::cpp11::next(arr.begin()); return 0; }