From 54b0fbc99a2d6f961e88403b077b4faadd67812e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 14 Jun 2010 16:24:10 +0000 Subject: [PATCH] add helper functions tuple_size and tuple_element for CGAL::cpp0x:tuple This is defined in cpp0x and tr1 but not in boost: in case boost::tuple is used, it relies on internal boost struct. --- STL_Extension/include/CGAL/tuple.h | 13 ++++++++++++ .../test/STL_Extension/test_stl_extension.cpp | 20 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/STL_Extension/include/CGAL/tuple.h b/STL_Extension/include/CGAL/tuple.h index 627fb85c367..f8cd14b608a 100644 --- a/STL_Extension/include/CGAL/tuple.h +++ b/STL_Extension/include/CGAL/tuple.h @@ -42,16 +42,29 @@ using std::tuple; using std::make_tuple; using std::tie; using std::get; +using std::tuple_size; +using std::tuple_element; #elif !defined CGAL_CFG_NO_TR1_TUPLE using std::tr1::tuple; using std::tr1::make_tuple; using std::tr1::tie; using std::tr1::get; +using std::tr1::tuple_size; +using std::tr1::tuple_element; #else using boost::tuple; using boost::make_tuple; using boost::tie; using boost::get; + +//tuple_size +template +struct tuple_size:public boost::tuples::length {}; + +//tuple_element +template +struct tuple_element: public boost::tuples::element{}; + #endif } // cpp0x diff --git a/STL_Extension/test/STL_Extension/test_stl_extension.cpp b/STL_Extension/test/STL_Extension/test_stl_extension.cpp index 3666d99fcc6..e4fd55710f4 100644 --- a/STL_Extension/test/STL_Extension/test_stl_extension.cpp +++ b/STL_Extension/test/STL_Extension/test_stl_extension.cpp @@ -44,6 +44,7 @@ #include #include #include +#include using namespace CGAL; @@ -8987,6 +8988,24 @@ void test_Quadruple() if (x2 == y2) x4.third = x3; } +void test_tuple(){ + typedef CGAL::cpp0x::tuple<> T0; + typedef CGAL::cpp0x::tuple T1; + typedef CGAL::cpp0x::tuple T2; + + + BOOST_STATIC_ASSERT( CGAL::cpp0x::tuple_size::value == 0 ); + BOOST_STATIC_ASSERT( CGAL::cpp0x::tuple_size::value == 2 ); + BOOST_STATIC_ASSERT( CGAL::cpp0x::tuple_size::value == 4 ); + BOOST_STATIC_ASSERT( (boost::is_same::type,My_to_int>::value) ); + + T1 t1=CGAL::cpp0x::make_tuple(1,2); + int i1=-1,i2=-1; + CGAL::cpp0x::tie(i1,i2)=t1; + CGAL_assertion( CGAL::cpp0x::get<0>(t1)==i1 ); + CGAL_assertion( CGAL::cpp0x::get<1>(t1)==i2 ); +} + void test_predecessor_successor() { std::vector V; @@ -9018,6 +9037,7 @@ int main() { test_Quadruple(); test_predecessor_successor(); clean_global_data(); + test_tuple(); return 0; } // EOF //