From 2cd1422514a4dd5f18dd8cfc77cfcf8b82c47b2e Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Mon, 19 Mar 2001 17:31:27 +0000 Subject: [PATCH] added comment about abstract base classes as value_type [SVN r9584] --- iterator_adaptors.htm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/iterator_adaptors.htm b/iterator_adaptors.htm index 8aa9e63..7dbd325 100644 --- a/iterator_adaptors.htm +++ b/iterator_adaptors.htm @@ -170,7 +170,8 @@ struct iterator_adaptor; The value_type of the resulting iterator, unless const. If Value is const X the value_type will be (non-const) X[1].
+ "#1">[1]. If the value_type you wish to use is an abstract + base class see note [5].
Default: std::iterator_traits<BaseType>::value_type [2] @@ -829,6 +830,20 @@ bool operator==(const iterator_adaptor<B1,P,V1,R1,P1,C,D>&, returning a reference could cause serious memory problems due to the reference being bound to a temporary object whose lifetime ends inside of the operator[]. + +

[5] + The value_type of an iterator may not be + an abstract base class, however many common uses of iterators + never need the value_type, only the reference type. + If you wish to create such an iterator adaptor, use a dummy + type such as char for the Value parameter, + and use a reference to your abstract base class for + the Reference parameter. Note that such an iterator + does not fulfill the C++ standards requirements for a + + Forward Iterator, so you will need to use a less restrictive + iterator category such as std::input_iterator_tag. +


Revised