|
Boost : |
From: Anatoli Tubman (anatoli_at_[hidden])
Date: 2004-04-22 09:23:14
John Torjo wrote:
>
> However, had I used
> crange<int> r(d); // how do I know what iterators to keep inside?
> crange<int> r(v); // how do I know what iterators to keep inside?
You keep a pointer to crange_impl_base<int> which points to a
heap-allocated instance of crange_impl<int, d_array> (or
crange_impl<int, v_array> or what have you) which is derived from
crange_impl_base<int> and knows what iterators to keep inside. Not very
efficient, but not technically impossible either.
Another option is to write
for (crange<int>& r = mkrange(d); r; ++r) { ... }
where mkrange returns crange_impl<int, d_array> which is derived from
crange<int>.
This doesn't need heap allocation, but still needs virtual operator++
and virtual operator*. A smart compiler could in theory inline them
anyway, but I wouldn't count on it.
-- Anatoli Tubman PTC Israel (Haifa) Tel. (+972) 4-8550035 ext. 229
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk