Opened 13 years ago

Last modified 13 years ago

#3044 new Bugs

mpl::aux_::iter_fold_if_impl allows deref l_end

Reported by: cppljevans@… Owned by: Aleksey Gurtovoy
Milestone: Boost 1.40.0 Component: mpl
Version: Boost 1.38.0 Severity: Problem
Keywords: Cc:

Description

The mpl::aux_::iter_fold_if_impl template:

https://svn.boost.org/trac/boost/browser/trunk/boost/mpl/aux_

/iter_fold_if_impl.hpp

allows deref'ing of an end iterator. The problem is most easily shown with list because deref<l_end> is not possible. Apparently, deref of an end iterator from other sequences (e.g. vector or range_c) allow deref of an end iterator.

The attached:

iter_fold_if_bkprotect.zip

illustrates the problem. The attached:

iter_fold_if_bkprotect2.zip

illustrates the cause. The attached:

while.cpp

illustrates a solution. However, the while.cpp suffers from the template instantiation depth problem described here:

http://www.mywikinet.com/mpl/paper

/mpl_paper.html#sequences.unrolling

More (*maybe* helpful) details can be found at the following boost ml thread:

http://thread.gmane.org/gmane.comp.lib.boost.devel/187289

Attachments (6)

iter_fold_if_bkprotect.zip (3.2 KB ) - added by cppljevans@… 13 years ago.
shows bug
iter_fold_if_bkprotect2.zip (6.1 KB ) - added by cppljevans@… 13 years ago.
shows bug cause
while.cpp (9.3 KB ) - added by cppljevans@… 13 years ago.
possible solution
iter_fold_if.patch (7.7 KB ) - added by Steven Watanabe 13 years ago.
while_recur.cpp (18.3 KB ) - added by cppljevans@… 13 years ago.
while.cpp replacement: while_recur (no unroll) while_unroll_recur(does unrolling)
while_recur.2.cpp (18.3 KB ) - added by cppljevans@… 13 years ago.
while.cpp replacement: while_recur (no unroll) while_unroll_recur(does unrolling)

Download all attachments as: .zip

Change History (9)

by cppljevans@…, 13 years ago

Attachment: iter_fold_if_bkprotect.zip added

shows bug

by cppljevans@…, 13 years ago

Attachment: iter_fold_if_bkprotect2.zip added

shows bug cause

by cppljevans@…, 13 years ago

Attachment: while.cpp added

possible solution

comment:1 by Steven Watanabe, 13 years ago

Component: Nonempl
Owner: set to Aleksey Gurtovoy

comment:2 by Steven Watanabe, 13 years ago

Patch attached. The reverse predicate doesn't add any significant functionality, and complicates the implementation, so I removed it entirely. Since iter_fold_if with a reverse operation doesn't work currently, this shouldn't break existing code.

by Steven Watanabe, 13 years ago

Attachment: iter_fold_if.patch added

by cppljevans@…, 13 years ago

Attachment: while_recur.cpp added

while.cpp replacement: while_recur (no unroll) while_unroll_recur(does unrolling)

by cppljevans@…, 13 years ago

Attachment: while_recur.2.cpp added

while.cpp replacement: while_recur (no unroll) while_unroll_recur(does unrolling)

comment:3 by cppljevans@…, 13 years ago

Please ignore attachment, while_recur.2.cpp. It's just an accidental copy of while_recur.cpp.

While_recur.cpp is essentially the while.cpp attachment with template, while_recur, as a renamed while_ of the while.cpp attachment. ALso while_recur.cpp has the while_unroll_recur template which is an "unrolled" (to lessen the template instantiation depth problem mentioned in comments) version of while_recur. The macro, USE_WHILE_UNROLL, decides whether while_recur or while_unroll_recur is used.

Note: See TracTickets for help on using tickets.