[C++-sig] Retrieving lvalues using custom converters (numpy 1-D converters attached)
Ravi
lists_ravi at lavabit.com
Thu Oct 2 22:51:10 CEST 2008
On Thursday 02 October 2008 08:35:05 Neal Becker wrote:
> But, I needed to add simple_const_iter for const_iterator.
Figured it out, stupid oversight on my part (forgot some add_const in the
right places); replace the definition of simple_iter like so:
template < class Value >
class simple_iter
: public boost::iterator_facade< simple_iter<Value>,
Value,
boost::random_access_traversal_tag,
typename
boost::add_reference<Value>::type,
npy_intp >
{
private:
struct enabler {};
typedef typename boost::mpl::if_<typename boost::is_const<Value>::type,
const numpy_storage_array<T>,
numpy_storage_array<T>
>::type array_type;
public:
explicit simple_iter( array_type *a, npy_intp indx = 0 )
: array( a ), index( indx ) {}
template <class OtherValue>
simple_iter( simple_iter<OtherValue> const &other,
typename boost::enable_if<
boost::is_convertible< OtherValue*, Value* >, enabler
>::type = enabler() )
: array( other.array ), index( other.index ) {}
private:
friend class boost::iterator_core_access;
template <class> friend class simple_iter;
void increment() { ++index; }
void decrement() { --index; }
template <class OtherValue>
bool equal( simple_iter<OtherValue> const &other ) const
{
return index == other.index;
}
Value &dereference() const { return ( *array )[index]; }
void advance( npy_intp n ) { index += n; }
template <class OtherValue>
npy_intp distance_to( simple_iter<OtherValue> const &other ) const
{
return other.index - index;
}
private:
array_type *array;
npy_intp index;
};
More information about the Cplusplus-sig
mailing list