2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-22 05:22:45 +00:00

Renamed iterator_pair to iterator_range

[SVN r20508]
This commit is contained in:
Raoul Gough
2003-10-27 18:27:11 +00:00
parent 4c4676db3e
commit eaf784b024
4 changed files with 41 additions and 48 deletions

View File

@@ -1,10 +1,8 @@
// -*- mode:c++ -*-
//
// Header file algo_selector.hpp
//
// Automatic selection of container algorithms (and traits) for known
// container types (basically, all STL container instances, as well as
// iterator_pair instances).
// iterator_range instances).
//
// Copyright (c) 2003 Raoul M. Gough
//
@@ -31,7 +29,7 @@
#include <boost/python/suite/indexing/algorithms.hpp>
// Definitions of further supported types
#include <boost/python/suite/indexing/iterator_pair.hpp>
#include <boost/python/suite/indexing/iterator_range.hpp>
#include <set>
#include <map>
#include <list>
@@ -152,12 +150,12 @@ namespace boost { namespace python { namespace indexing {
// Iterator ranges
template <typename Iterator>
class selector_impl<iterator_pair<Iterator> >
class selector_impl<iterator_range<Iterator> >
{
typedef iterator_pair<Iterator> Container;
typedef iterator_range<Iterator> Container;
typedef iterator_pair_traits<Container> mutable_traits;
typedef iterator_pair_traits<Container const> const_traits; // ?
typedef iterator_range_traits<Container> mutable_traits;
typedef iterator_range_traits<Container const> const_traits; // ?
public:
typedef default_algorithms<mutable_traits> mutable_algorithms;

View File

@@ -1,5 +1,3 @@
// -*- mode:c++ -*-
//
// Header file container_traits.hpp
//
// Traits information about entire containers for use in determining
@@ -92,11 +90,11 @@ namespace boost { namespace python { namespace indexing {
};
/////////////////////////////////////////////////////////////////////////
// Traits for the iterator_pair container emulator
// Traits for the iterator_range container emulator
/////////////////////////////////////////////////////////////////////////
template<typename IteratorPair>
struct iterator_pair_traits : public base_container_traits<IteratorPair>
template<typename IteratorRange>
struct iterator_range_traits : public base_container_traits<IteratorRange>
{
};

View File

@@ -1,6 +1,4 @@
// -*- mode:c++ -*-
//
// Header file iterator_pair.hpp
// Header file iterator_range.hpp
//
// Emulate an STL container using a pair of iterators. Doesn't support
// insertion or deletion, for the obvious reasons.
@@ -13,13 +11,14 @@
//
// History
// =======
// 2003/ 9/ 9 rmg File creation
// 2003/ 9/ 9 rmg File creation as iterator_pair.hpp
// 2003/10/27 rmg Renamed iterator_range.hpp
//
// $Id$
//
#ifndef BOOST_PYTHON_INDEXING_ITERATOR_PAIR_HPP
#define BOOST_PYTHON_INDEXING_ITERATOR_PAIR_HPP
#ifndef BOOST_PYTHON_INDEXING_ITERATOR_RANGE_HPP
#define BOOST_PYTHON_INDEXING_ITERATOR_RANGE_HPP
#include <stdexcept>
#include <algorithm>
@@ -29,7 +28,7 @@
namespace boost { namespace python { namespace indexing {
template<typename Iterator>
class iterator_pair
class iterator_range
{
private:
typedef typename boost::call_traits<Iterator>::param_type iterator_param;
@@ -45,7 +44,7 @@ namespace boost { namespace python { namespace indexing {
typedef iterator const_iterator;
// Can't tell what the const version of our iterator should
// be. The client code will have to instantiate iterator_pair
// be. The client code will have to instantiate iterator_range
// directly with a const_iterator if that's what it wants.
// Also can't provide: allocator_type, reverse_iterator or
@@ -54,8 +53,8 @@ namespace boost { namespace python { namespace indexing {
// reference and pointer if Iterator is itself a const_iterator.
public:
iterator_pair (iterator_param, iterator_param);
iterator_pair (std::pair<iterator, iterator> const &);
iterator_range (iterator_param, iterator_param);
iterator_range (std::pair<iterator, iterator> const &);
iterator begin() const;
iterator end() const;
@@ -72,7 +71,7 @@ namespace boost { namespace python { namespace indexing {
};
template<typename Iterator>
iterator_pair<Iterator>::iterator_pair (
iterator_range<Iterator>::iterator_range (
iterator_param begin, iterator_param end)
: m_begin (begin)
, m_end (end)
@@ -80,37 +79,37 @@ namespace boost { namespace python { namespace indexing {
}
template<typename Iterator>
iterator_pair<Iterator>
::iterator_pair (std::pair<iterator, iterator> const &pair)
iterator_range<Iterator>
::iterator_range (std::pair<iterator, iterator> const &pair)
: m_begin (pair.first)
, m_end (pair.second)
{
}
template<typename Iterator>
typename iterator_pair<Iterator>::iterator
iterator_pair<Iterator>::begin() const
typename iterator_range<Iterator>::iterator
iterator_range<Iterator>::begin() const
{
return m_begin;
}
template<typename Iterator>
typename iterator_pair<Iterator>::iterator
iterator_pair<Iterator>::end() const
typename iterator_range<Iterator>::iterator
iterator_range<Iterator>::end() const
{
return m_end;
}
template<typename Iterator>
typename iterator_pair<Iterator>::size_type
iterator_pair<Iterator>::size() const
typename iterator_range<Iterator>::size_type
iterator_range<Iterator>::size() const
{
return std::distance (begin(), end());
}
template<typename Iterator>
typename iterator_pair<Iterator>::reference
iterator_pair<Iterator>::operator[](size_type index) const
typename iterator_range<Iterator>::reference
iterator_range<Iterator>::operator[](size_type index) const
{
iterator temp (begin());
std::advance (temp, index);
@@ -118,13 +117,13 @@ namespace boost { namespace python { namespace indexing {
}
template<typename Iterator>
typename iterator_pair<Iterator>::reference
iterator_pair<Iterator>::at (size_type index) const
typename iterator_range<Iterator>::reference
iterator_range<Iterator>::at (size_type index) const
{
if (index >= size())
{
throw std::out_of_range
(std::string ("iterator_pair: index out of range"));
(std::string ("iterator_range: index out of range"));
}
else
@@ -144,4 +143,4 @@ namespace boost { namespace python { namespace indexing {
}
} } }
#endif // BOOST_PYTHON_INDEXING_ITERATOR_PAIR_HPP
#endif // BOOST_PYTHON_INDEXING_ITERATOR_RANGE_HPP

View File

@@ -1,5 +1,3 @@
// -*- mode:c++ -*-
//
// Module test_array_ext.cpp
//
// Copyright (c) 2003 Raoul M. Gough
@@ -18,7 +16,7 @@
#include "int_wrapper.hpp"
#include <boost/python/suite/indexing/container_suite.hpp>
#include <boost/python/suite/indexing/iterator_pair.hpp>
#include <boost/python/suite/indexing/iterator_range.hpp>
#include <boost/python/class.hpp>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
@@ -28,23 +26,23 @@
bool int_wrapper::our_trace_flag = true;
unsigned int_wrapper::our_object_counter = 0;
boost::python::indexing::iterator_pair<int *> get_array_plain()
boost::python::indexing::iterator_range<int *> get_array_plain()
{
static int array[] = { 8, 6, 4, 2, 1, 3, 5, 7, 0 };
return boost::python::indexing::iterator_pair<int *>
return boost::python::indexing::iterator_range<int *>
(boost::python::indexing::begin(array)
, boost::python::indexing::end(array));
}
boost::python::indexing::iterator_pair<int_wrapper *> get_array_wrap()
boost::python::indexing::iterator_range<int_wrapper *> get_array_wrap()
{
static int_wrapper array[] = {
int_wrapper(8), int_wrapper(6), int_wrapper(4), int_wrapper(2)
, int_wrapper(1), int_wrapper(3), int_wrapper(5)
, int_wrapper(7), int_wrapper(0) };
return boost::python::indexing::iterator_pair<int_wrapper *>
return boost::python::indexing::iterator_range<int_wrapper *>
(boost::python::indexing::begin(array)
, boost::python::indexing::end(array));
}
@@ -61,7 +59,7 @@ BOOST_PYTHON_MODULE(test_array_ext)
.def ("__cmp__", compare)
;
typedef boost::python::indexing::iterator_pair<int *> Container1;
typedef boost::python::indexing::iterator_range<int *> Container1;
boost::python::class_<Container1>
("Array", boost::python::init<int *, int *>())
@@ -69,12 +67,12 @@ BOOST_PYTHON_MODULE(test_array_ext)
boost::python::def ("get_array_plain", get_array_plain);
typedef boost::python::indexing::iterator_pair<int_wrapper *> Container2;
typedef boost::python::indexing::iterator_range<int_wrapper *> Container2;
// reference_existing_object is safe in this case, because the array
// is static, and we never manually destroy any array elements. There
// is also no point in using return_internal_reference to extend the
// life of the iterator_pair object, since it has no influence on the
// life of the iterator_range object, since it has no influence on the
// lifetimes of the array elements.
boost::python::class_<Container2>
("Array_ref", boost::python::init<int_wrapper *, int_wrapper *>())