|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2006-09-01 06:43:02
Joel de Guzman <joel_at_[hidden]> writes:
> David Abrahams wrote:
>> Joel de Guzman <joel_at_[hidden]> writes:
>>
>>> There's also an interesting
>>> use-case that became apparent recently: making arbitrary structs/classes
>>> conforming sequences easily-- as easy as providing a single function.
>>> Pardon me if this is rather sketchy at this point, but imagine
>>> being able to write:
>>>
>>> Our user defined struct:
>>>
>>> struct point { float x, float y; };
>>>
>>> Customization:
>>>
>>> fusion::map<keys::x_, keys::y_, float&, float&>
>>> as_fusion_sequence(point& p)
>>> {
>>> return fusion::map_tie<keys::x_, keys::y_>(p.x, p.y);
>>> }
>>>
>>> Use:
>>>
>>> point p = { 123.456, 789.012 };
>>> fusion::for_each(p, std::cout << _1 << std::endl);
>>
>> That's nice, but I don't think it's really the same thing. Doesn't it
>> incur an extra level of indirection?
>
> Not the same as what? Sorry, I think I missed something in
> your question/comment.
It's not really the same as making point actually *be* a conforming
fusion sequence, in some sense, is it? You've sorta "cheated" by
giving it a kind of implicitly-recognized conversion into a view.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk