|
Boost : |
From: Larry Evans (cppljevans_at_[hidden])
Date: 2005-07-07 16:51:32
On 07/01/2005 06:47 AM, Thorsten Ottosen wrote:
> Larry Evans <cppljevans <at> cox-internet.com> writes:
[snip]
>>Are there any plans to request a formal review so that it's eventually
>>in boost? I tried boost/range; however, as indicated by comments
>>in the above code, I had no luck.
>
> Could you make an small example that shows what you want to do and why
> boost.range cannot do it?
>
What I want is:
<-------- cut here --------
#include <utility>
using namespace std;
template<class StlContainer>
struct const_iter_range
: private std::pair
< typename StlContainer::const_iterator
, typename StlContainer::const_iterator
>
{
typedef
typename StlContainer::const_iterator
iter_type
;
typedef
typename StlContainer::const_reference
const_reference
;
typedef
std::pair<iter_type,iter_type>
super_type
;
const_iter_range(StlContainer const& a_container)
: super_type(a_container.begin(), a_container.end())
{}
const_reference
operator*(void)const
{
return *(this->first);
}
void
operator++(void)
{
++(this->first);
}
bool
empty(void)const
{
return (this->first) == (this->second);
}
};
>-------- cut here --------
However, when I tested boost/range by copying and then
simplifying libs/range/test/iterator_range.hpp, the
closest I got was:
<-------- cut here --------
typedef string::iterator iterator;
typedef iterator_range<iterator> irange;
string str = "hello world";
irange ir = make_iterator_range( str );
cout <<"print str:\n";
cout <<str<<"\n";
cout <<"iterating thru ri:\n";
range_iterator<string>::type ri(begin(ir));
for
( int i=0
; i<2
//&& !(ri.empty())
; ++i,++ri
)
{
cout <<*ri << "\n";
}
return 0;
}-------- cut here --------
Why doesn't range_iterator<X> have an empty method?
It also seems a lot of trouble to first declare and
initialize the iterator_range used as argument to
range_iterator. What's the reason for not doing
this directly from the iterator_range CTOR arg
which could just be an stl container?
I suspect I missed something, but it's not obvious,
at least to me :(
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk