|
Boost : |
From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2005-05-11 13:46:19
"Peter Dimov" <pdimov_at_[hidden]> wrote in message
news:007301c55654$256e3bb0$6401a8c0_at_pdimov2...
| Thorsten Ottosen wrote:
| > "Anthony Williams" <anthony_w.geo_at_[hidden]> wrote in message
| > news:fywten01.fsf_at_yahoo.com...
| >> If the implementation uses free standing functions, you need to
| >> write begin() and end() for your type. If the implementation uses
| >> members, you can write make_range() for your type, *or* write the
| >> members.
| >
| > yep, but the latter approach is harder and takes just about twice as
| > much code in C++0x.
|
| Can you elaborate, please?
sure.
as a free-standing function we can say
template< class T >
auto begin( MyType<T>&& r ) -> decltype( r.Begin() )
{
return r.Begin();
}
for( const auto& r : my_obj )
{ ... }
with an adapter class we need to say
struct my_type_adapter
{
MyType& ref;
my_type_adapter( MyType&& r ) : ref(r)
{ }
decltype( ref.Begin() ) begin()
{ return ref.Begin(); }
};
for( const auto& r : my_type_adapter( my_obj ) )
{ ... }
or something.
-Thorsten
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk