Any real-world need for static_cast_iterator, const_cast_iterator, dynamic_cast_iterator?

In addition to the specialised adaptors in the boost iterator library, does it make any sense to add: static_cast_iterator const_cast_iterator dynamic_cast_iterator ...iterator adaptors providing embedded static_cast<>, const_cast<> or dynamic_cast<> when dereferencing? (Rather than just throwing them straight on the scrap heap...) - Nigel ---------------------------------------------- template<typename T, typename I> class static_cast_iterator : public boost::transform_iterator < T (*)(const typename I::reference), I > { private: typedef typename I::reference F; typedef typename boost::transform_iterator< T (*)(const F), I> B; public: static_cast_iterator() {} static_cast_iterator(const I &i) : B(i,&doCast) {} operator const I &() const { return B::base(); } static_cast_iterator &operator++() { B::operator++(); return *this; } static_cast_iterator &operator--() { B::operator--(); return *this; } private: static T doCast(const F val) { return static_cast<T>(val); } }; template<typename I> class const_cast_iterator : public boost::transform_iterator < typename boost::remove_const<typename I::reference>::type (*)(const typename I::reference), I > { private: typedef typename I::reference F; typedef typename boost::remove_const<F>::type T; typedef typename boost::transform_iterator< T (*)(const F), I> B; BOOST_STATIC_ASSERT(boost::is_const<F>::value); BOOST_STATIC_ASSERT(!boost::is_const<T>::value); public: const_cast_iterator() {} const_cast_iterator(const I &i) : B(i,&doCast) {} operator const I &() const { return B::base(); } const_cast_iterator &operator++() { B::operator++(); return *this; } const_cast_iterator &operator--() { B::operator--(); return *this; } private: static T doCast(const F val) { return const_cast<T>(val); } }; template<typename T, typename I> class dynamic_cast_iterator : public boost::transform_iterator < T (*)(const typename I::reference), I > { private: typedef typename I::reference F; typedef typename boost::transform_iterator< T (*)(const F), I> B; BOOST_STATIC_ASSERT(boost::is_pointer<F>::value || boost::is_reference<F>::value); BOOST_STATIC_ASSERT(boost::is_pointer<T>::value || boost::is_reference<T>::value); public: dynamic_cast_iterator() {} dynamic_cast_iterator(const I &i) : B(i,&doCast) {} operator const I &() const { return B::base(); } dynamic_cast_iterator &operator++() { B::operator++(); return *this; } dynamic_cast_iterator &operator--() { B::operator--(); return *this; } private: static T doCast(const F val) { return dynamic_cast<T>(val); } };

Nigel Stewart wrote:
In addition to the specialised adaptors in the boost iterator library, does it make any sense to add:
static_cast_iterator const_cast_iterator dynamic_cast_iterator
...iterator adaptors providing embedded static_cast<>, const_cast<> or dynamic_cast<> when dereferencing? (Rather than just throwing them straight on the scrap heap...)
Personally, I've had much use of a custom made match<Type>() adaptor (using the Boost.RangeEx pipe syntax), that performs a transform with dynamic_pointer_cast and then filters null results.

Personally, I've had much use of a custom made match<Type>() adaptor (using the Boost.RangeEx pipe syntax), that performs a transform with dynamic_pointer_cast and then filters null results.
The idea would be to skip items that dynamic cast to NULL in the operator++() and operator--()? Except that I'm not sure how to detect the end of the container... ... sounds interesting... - Nigel

Nigel Stewart wrote:
Personally, I've had much use of a custom made match<Type>() adaptor (using the Boost.RangeEx pipe syntax), that performs a transform with dynamic_pointer_cast and then filters null results.
The idea would be to skip items that dynamic cast to NULL in the operator++() and operator--()? Except that I'm not sure how to detect the end of the container... ... sounds interesting...
range | match<Type>() is just like range | transformed(dynamic_cast_<Type>(_1)) | filtered(_1) (assuming my lambdas are correct)

On Tue, Feb 3, 2009 at 01:30, Nigel Stewart <nigels@nigels.com> wrote:
In addition to the specialised adaptors in the boost iterator library, does it make any sense to add:
static_cast_iterator const_cast_iterator dynamic_cast_iterator
...iterator adaptors providing embedded static_cast<>, const_cast<> or dynamic_cast<> when dereferencing? (Rather than just throwing them straight on the scrap heap...)
It seems like they would just be transform_iterator with ll_whichever_cast. Is providing them separately worth it?

static_cast_iterator const_cast_iterator dynamic_cast_iterator
It seems like they would just be transform_iterator with ll_whichever_cast. Is providing them separately worth it?
Yes indeed, I'm asking myself the same question. At least they're now archived here on this list... - Nigel
participants (3)
-
Mathias Gaunard
-
Nigel Stewart
-
Scott McMurray