add non-documented remove_const fcts to turn a const-iterator to an iterator

This commit is contained in:
Sébastien Loriot 2014-06-24 16:35:10 +02:00
parent 55d9d30f26
commit 675d26e884
4 changed files with 45 additions and 2 deletions

View File

@ -164,6 +164,11 @@ namespace internal {
--*this; --*this;
return tmp; return tmp;
} }
In_place_list_iterator<T,Alloc>
remove_const() const
{
return In_place_list_iterator<T,Alloc>(const_cast<T*>(node));
}
}; };
} }

View File

@ -32,6 +32,9 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <cstddef> #include <cstddef>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_pointer.hpp>
namespace CGAL { namespace CGAL {
@ -118,6 +121,24 @@ public:
bool operator> ( const Self& i) const { return i < *this; } bool operator> ( const Self& i) const { return i < *this; }
bool operator<=( const Self& i) const { return !(i < *this); } bool operator<=( const Self& i) const { return !(i < *this); }
bool operator>=( const Self& i) const { return !(*this < i); } bool operator>=( const Self& i) const { return !(*this < i); }
vector_iterator< T,
typename boost::remove_const<
typename boost::remove_reference<Ref>::type
>::type&,
typename boost::remove_const<
typename boost::remove_pointer<Ptr>::type
>::type* >
remove_const() const
{
typedef typename boost::remove_const<
typename boost::remove_pointer<Ptr>::type
>::type* Ptr_no_c;
return vector_iterator< T,
typename boost::remove_const<typename boost::remove_reference<Ref>::type>::type&,
Ptr_no_c>
( const_cast<Ptr_no_c>(ptr) );
}
}; };
template < class T, class Ref, class Ptr> inline template < class T, class Ref, class Ptr> inline

View File

@ -888,6 +888,7 @@ void test_In_place_list() {
{ {
typedef CGAL::In_place_list<Cont,false> ContList; typedef CGAL::In_place_list<Cont,false> ContList;
typedef CGAL::In_place_list<Cont,false>::iterator Iterator; typedef CGAL::In_place_list<Cont,false>::iterator Iterator;
typedef CGAL::In_place_list<Cont,false>::const_iterator Const_iterator;
ContList L; ContList L;
L.push_back(* new Cont(3)); L.push_back(* new Cont(3));
@ -902,6 +903,13 @@ void test_In_place_list() {
assert( (*it1).i_ <= (*it2).i_ ); assert( (*it1).i_ <= (*it2).i_ );
} }
// test remove_const
Const_iterator cit=L.begin();
Iterator it=cit.remove_const();
CGAL_USE(cit);
CGAL_USE(it);
L.destroy(); L.destroy();
} }

View File

@ -33,6 +33,7 @@
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <list> #include <list>
#include <CGAL/use.h>
class X { class X {
public: public:
@ -213,5 +214,13 @@ int main() {
assert( V7.size() == 16); assert( V7.size() == 16);
std::cout << "done" << std::endl; std::cout << "done" << std::endl;
// test remove_const
const_iterator mycit=V3.begin();
iterator myit=cit.remove_const();
iterator myit2=myit.remove_const();
CGAL_USE(mycit);
CGAL_USE(myit);
CGAL_USE(myit2);
return 0; return 0;
} }