mirror of https://github.com/CGAL/cgal
Merge from /branches/features/STL_Extension-better_cpp0x_get-lrineau
This commit is contained in:
commit
e37e88c8f3
|
|
@ -33,7 +33,8 @@ is taken from Boost.
|
|||
|
||||
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},
|
||||
\ccc{get}, \ccc{tie}.
|
||||
\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}).
|
||||
|
||||
\end{ccRefClass}
|
||||
|
|
|
|||
|
|
@ -27,12 +27,15 @@
|
|||
|
||||
#ifndef CGAL_CFG_NO_CPP0X_TUPLE
|
||||
# include <tuple>
|
||||
#elif !defined CGAL_CFG_NO_TR1_TUPLE
|
||||
# include <tr1/tuple>
|
||||
#else
|
||||
# include <boost/tuple/tuple.hpp>
|
||||
# include <boost/tuple/tuple_comparison.hpp>
|
||||
#endif
|
||||
#ifndef CGAL_CFG_NO_TR1_TUPLE
|
||||
# include <tr1/tuple>
|
||||
# include <tr1/utility>
|
||||
#endif
|
||||
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/tuple/tuple_comparison.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
|
|
@ -68,6 +71,47 @@ struct tuple_element: public boost::tuples::element<N,T>{};
|
|||
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(CGAL_CFG_NO_CPP0X_TUPLE) && defined(CGAL_CFG_NO_TR1_TUPLE)
|
||||
// If not TR1 or C++11 tuple, we need to add get<N>(std::pair).
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Allow CGAL::cpp0x::get<N>(std::pair), if N==0 or N==1. //
|
||||
// //
|
||||
// That is already in TR1 and C++11, but not in Boost. //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////
|
||||
template <std::size_t N, typename T1, typename T2>
|
||||
struct pair_get;
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct pair_get<0, T1, T2> {
|
||||
static T1& get(std::pair<T1, T2>& pair) { return pair.first; }
|
||||
static const T1& get(const std::pair<T1, T2>& pair) { return pair.first; }
|
||||
}; // end specialization struct pair_get<0, T2, T2>
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct pair_get<1, T1, T2> {
|
||||
static T2& get(std::pair<T1, T2>& pair) { return pair.second; }
|
||||
static const T2& get(const std::pair<T1, T2>& pair) { return pair.second; }
|
||||
}; // end specialization struct pair_get<0, T2, T2>
|
||||
|
||||
template <std::size_t N, typename T1, typename T2>
|
||||
inline typename boost::tuples::element<N, boost::tuple<T1, T2> >::type&
|
||||
get(std::pair<T1, T2>& pair) {
|
||||
return pair_get<N, T1, T2>::get(pair);
|
||||
}
|
||||
|
||||
template <std::size_t N, typename T1, typename T2>
|
||||
inline const typename boost::tuples::element<N, boost::tuple<T1, T2> >::type&
|
||||
get(const std::pair<T1, T2>& pair) {
|
||||
return pair_get<N, T1, T2>::get(pair);
|
||||
}
|
||||
|
||||
#endif // end if not C++11 tuple
|
||||
|
||||
|
||||
} // cpp0x
|
||||
|
||||
#ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES
|
||||
|
|
|
|||
|
|
@ -8110,10 +8110,7 @@ void test_tuple(){
|
|||
|
||||
T1 t1=CGAL::cpp0x::make_tuple(1,2);
|
||||
T1 t1_2=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 );
|
||||
|
||||
CGAL_assertion(t1==t1_2); // test the equality operator
|
||||
|
||||
// T2 t2 = T2();
|
||||
|
|
@ -8122,6 +8119,22 @@ void test_tuple(){
|
|||
// Do not test equality between default initialized tuples, because
|
||||
// GNU/g++ version 4.1.2 does not default-initialize correctly
|
||||
// std::tr1::tuple.
|
||||
|
||||
// Test CGAL::cpp0x::tie
|
||||
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 );
|
||||
|
||||
// Test CGAL::cpp0x::get for a pair
|
||||
double d = 1;
|
||||
std::pair<int, double *> pair(-3, &d);
|
||||
const std::pair<int, double *> const_pair(2, &d);
|
||||
|
||||
assert(CGAL::cpp0x::get<0>(pair) == -3);
|
||||
assert(CGAL::cpp0x::get<1>(pair) == &d);
|
||||
assert(CGAL::cpp0x::get<0>(const_pair) == 2);
|
||||
assert(CGAL::cpp0x::get<1>(const_pair) == &d);
|
||||
}
|
||||
|
||||
void test_prev_next()
|
||||
|
|
|
|||
Loading…
Reference in New Issue