Boost logo

Boost :

Subject: Re: [boost] [log][phoenix] Questions on porting to phoenix
From: TONGARI (tongari95_at_[hidden])
Date: 2012-01-24 04:54:15


2012/1/24 Andrey Semashev <andrey.semashev_at_[hidden]>

[...]

> A few more questions, if I may.
>
> 1. I would like to cache some data in the actor at the point of AST
> construction. For instance, I'd like to cache the attribute name (in
> the actual code it's not really a string but rather an adapter
> constructible from a string; I'd like to avoid its construction at the
> expression evaluation time) and, possibly, a default value for the
> attribute. Is this possible? The attribute keyword should still be a
> POD (or at least, be safely constructible at the namespace scope), so
> the cached data can only be provided only by a function call.
>
> 2. I would like the keyword have additional methods, in particular,
> for default attribute value provision. Extending my initial syntax,
> this would be:
>
> BOOST_LOG_REGISTER_ATTRIBUTE("Severity", severity, my_severity)
>
> attribute_values_view attrs;
>
> severity(attrs); // returns optional<my_severity>
> severity.or_default(info)(attrs); // returns my_severity, which is
> info by default
>
> As I understand, the only way I can do that, except for reimplementing
> phoenix::actor, is to derive my actor from phoenix::actor. This makes
> the attribute keyword non-POD in C++03 but is it still safe to be
> constructed in the namespace scope, provided that the keyword does not
> have its own data members?

I'm not sure as well, that's what I always want to ask Eric:
http://www.boost.org/doc/libs/1_48_0/doc/html/proto/appendices.html#boost_proto.appendices.rationale.static_initialization

Anyway, I played a trick while not knowing if it's available.
The idea is:

    struct Pod {...you could have some data...};
    struct Derived : Pod {}; // non-POD in C++03
    Pod p_base = {...some data...}; // statically initialized
    Derived& p = static_cast<Derived&>(p_base); // statically initialized,
not?

Also, what should be the template argument
> for the phoenix::actor specialization? Here's the code example to
> illustrate what I'm talking about:
>

[...]

Again, I wrote the sample code (a rewrite from my last sample).
I store the attribute name, this way, you don't need a new type for each
keyword (which could be of the same value_type).

Oh, BTW, I hope I can have severity(attrs) return optional<my_severity
const&> instead of optional<my_severity> in case that my_severity is heavy
(not this case, I know), but then the comparison ops are lost :(

HTH




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk