Boost C++ Libraries: Ticket #5463: default constructor of filter_iterator does not initialize members https://svn.boost.org/trac10/ticket/5463 <p> filter_iterator initializes neither m_predicate nor m_end in its default constructor. Not initializing m_end in case when it is a pointer (or any other built in type) results in a random bahavior of end() method. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5463 Trac 1.4.3 Steven Watanabe Tue, 12 Apr 2011 22:43:50 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5463#comment:1 https://svn.boost.org/trac10/ticket/5463#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> A default constructed filter iterator is considered singular. You should not expect to do anything with it, any more than you can expect a default constructed pointer to behave in a useful way. </p> Ticket anonymous Wed, 13 Apr 2011 01:46:53 GMT <link>https://svn.boost.org/trac10/ticket/5463#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5463#comment:2</guid> <description> <p> 2 default constructed pointers are equal (if they are initialized). Why wouldn't iterators be? The current iterator behavior changes between different compilers/modes. Make the constructor private if you do not want it to be used. Making it not deterministic is not helping. Why would one expose a nondeterministic method? </p> <p> Is there any argument why not to initialize members of the iterator? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Dave Abrahams</dc:creator> <pubDate>Wed, 13 Apr 2011 03:19:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5463#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5463#comment:3</guid> <description> <p> A pointer can't be both default constructed <em>and</em> initialized, by definition. The default constructor is deterministic if you only do the things allowed with singular iterators: assign-to-them and destroy-them. There is an efficiency argument for not initializing members, and besides, the default constructed members that are themselves iterators would still be singular, so in the generic case, it wouldn't help you. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 13 Apr 2011 03:48:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5463#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5463#comment:4</guid> <description> <p> There is one more additional use of singular iterators - like in case of istream_iterator. They can be compared with an other iterator to check agains end condition. It may be far more useful then calling "end" method from the iterator class. Please read my example below. </p> <p> I do not agree with the efficiency argument, as only if the iterator encapsulated by filter_iterator is a class, it's constructor is called anyway. I do not think simple types initialization cost justifies leaving it uninitialized. </p> <p> It would help in my particular case. I have an iterator encapsulating a filter_iterator on top of a predicate and an array. I relay on the fact the instances of my iterator default constructed are equal. I pass to boost::minmax 2 arguments: </p> <ul><li>a non-default constructed instance of my iterator, initialized with the filter iterator initialized with an array. </li><li>a default constructed iterator, what encapsulates default constructed filter iterator which indicates the end (like in istream_iterator) </li></ul><p> I check result of minmax, that returns a pair of iterators having my type. In order to check if they are end iterators, I compare each with default constructed iterator. <em>I do not have access to "internal", filter_iterator anymore, but I can construct a new "end iterator" and compare.</em> </p> <p> It will work, only if encapsulated filter iterators, default initialized, will be equal to the "end" iterator I passed to boost::minmax. In order to achieve that filter iterators have to be equal, so the iterator they encapsulate have to be initialized (to be equal). And they are for any other than simple type case. </p> <p> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Dave Abrahams</dc:creator> <pubDate>Wed, 13 Apr 2011 14:06:00 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5463#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5463#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/5463#comment:4" title="Comment 4">anonymous</a>: </p> <blockquote class="citation"> <p> There is one more additional use of singular iterators - like in case of istream_iterator. They can be compared with an other iterator to check agains end condition. </p> </blockquote> <p> No, please consult the standard. Singular iterators can't be compared. </p> <blockquote> <p> For that particular iterator type, default-construction does not produce a singular iterator. </p> </blockquote> <blockquote class="citation"> <p> It may be far more useful then calling "end" method from the iterator class. </p> </blockquote> <p> “"end" method?” </p> <blockquote class="citation"> <p> Please read my example below. </p> <p> I do not agree with the efficiency argument, as only if the iterator encapsulated by filter_iterator is a class, it's constructor is called anyway. I do not think simple types initialization cost justifies leaving it uninitialized. </p> </blockquote> <p> Probably it doesn't in your application and in many others, but libraries have broad constituencies. </p> <blockquote class="citation"> <p> It would help in my particular case. I have an iterator encapsulating a filter_iterator on top of a predicate and an array. I relay on the fact the instances of my iterator default constructed are equal. I pass to boost::minmax 2 arguments: </p> <ul><li>a non-default constructed instance of my iterator, initialized with the filter iterator initialized with an array. </li><li>a default constructed iterator, what encapsulates default constructed filter iterator which indicates the end (like in istream_iterator) </li></ul><p> I check result of minmax, that returns a pair of iterators having my type. In order to check if they are end iterators, I compare each with default constructed iterator. <em>I do not have access to "internal", filter_iterator anymore, </em></p> </blockquote> <p> The <code>.base()</code> member function doesn't work for this purpose? </p> <blockquote class="citation"> <p> but I can construct a new "end iterator" and compare.<em> </em></p> <p> It will work, only if encapsulated filter iterators, default initialized, will be equal to the "end" iterator I passed to boost::minmax. In order to achieve that filter iterators have to be equal, so the iterator they encapsulate have to be initialized (to be equal). And they are for any other than simple type case. </p> </blockquote> <p> I'm sorry, I can't understand what you're describing well enough. Perhaps if you attached some code... </p> </description> <category>Ticket</category> </item> </channel> </rss>