Boost logo

Boost :

From: Brian McNamara (lorgon_at_[hidden])
Date: 2003-11-05 05:37:58

On Wed, Nov 05, 2003 at 03:38:37PM +0800, Joel de Guzman wrote:
> I tried to replace this with Brian's code, but the regression tests
> failed. Why? Because [where o is an optional<T> and v is a T ] *o = v
> only works when o is initialized, while o = v works even if o is
> uninitialized. IOTW, I need this to work:
> match<int> m; // unitialized
> m.value(3); // initializes m
> So, Brian, to answer your question "So does my code above work for
> you?", well, unfortunately, not. I am now inclined to believe that,
> indeed, "If it ain't broke, don't fix it". However, in this case, "it"
> means ***the tried and true C++ reference semantics***.
> Thoughts?

I am a little unclear about the semantics of match, so I need to ask
some more questions to try to understand it. Your original use case was

> match<T> m(i);
> m.value(x); // ok, set the attribute to x
> match<T&> m(r);
> m.value(x); // NO, please don't reset the reference, that's not
> // what I want! references should only be set
> // *at construction time*. I want the thing referenced
> // by r set to x.

and so I didn't realize that match could also have a default
constructor and hence I didn't forsee this problem.

So we need to also add this use case, I guess:

> match<int> m; // unitialized
> m.value(3); // initializes m

Is this:

> match<int&> m; // unitialized
> m.value(3); // initializes m

also supposed to be legal? I am guessing no, (for the same reason that
you can't say "int& x;") but I am not sure.

Who actually creates match objects? The parser? When is the default
constructor called? (Maybe when a parse fails, but we still need to
return a match object?) When is the non-default constructor called?
(Maybe when the parse succeeds?)

When is the value(x) method called? (I have no clue here.) What is
its semantics supposed to be? Does it convert an "empty" match into a
"full" one? Or does it just change/update the value of a "full"
match? Or both?

(I have been trying to look through the Spirit code in Boost to see if I
can figure out answers to this myself, but I've been unsuccessful. I
found the match class, but I can't seem to find anywhere that someone
constructs an instance of the match class. Clearly I'm looking in the
wrong places. :) )

-Brian McNamara (lorgon_at_[hidden])

Boost list run by bdawes at, gregod at, cpdaniel at, john at