Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-01-24 17:43:09


Larry Evans <cppljevans_at_[hidden]> writes:

> On 01/20/2006 10:00 AM, David Abrahams wrote:
> [snip]
>> I hope you're reusing the visitor mechanism provided by the signals
>> library for function detection:
>> http://www.boost.org/doc/html/signals/s05.html#id2739308
>>
> From looking at:
>
> template<typename V>
> void visit_each(V& v, const tracking_bridge& t, int)
> {
> v(t);
> v(t.sig);
> }
>
> in $BOOST_ROOT/libs/signals/test/random_signal_system.cpp, I realized
> the meaning of:
>
> a visit_each overload must be supplied for each object type.
>
> in http://www.boost.org/doc/html/visit_each.html, i.e. the user must
> explicitly call v(x) for each subobject, x, of T.

Correct.

> However, the phrase, 'for each subobject' in visit_each.html
> is not really accurate since there is the subobject:
>
> minstd_rand& tracked_bridge::rand_gen;
>
> in tracking_bridge.

Technically speaking, that code is wrong and the phrase is accurate.

> Maybe "subobjects selected by user in the user's specialization of
> visit_each" would be more accurate.

I don't think so. That's tautological.

> Anyway, the essential difference
> is that with visit_each, the user has to know which subobjects to
> visit and has to explicitly code the visit. OTOH, with fields_visitor,
> the user can select

??

> the object by "declaring" it visitable by wrapping
> it in something derived from registrar_heirarchy.

I don't see how wrapping the object is going to tell your registrar
where the subobjects are.

> The visit_each method is less intrusive (no need to modify the class
> to be visited), but more work.
>
> The following code:
>
> http://tinyurl.com/dx7rs
>
> demonstrates how fields_visitor can be used to emulate a visit_each
> method.

A lot of code, almost no comments. It's not very clear what it's
supposed to be doing or illustrating.

> The other example program, simple_*.cpp, shows how to do it just
> using fields_visitor.

where is that? You must mean simple_record_field_traversal_test.cpp

Also not very clear to me. The use of "arg<1>" instead of "_1" is not
very idiomatic, which --though it's minor-- doesn't help, IMO.

-- 
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