Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-02-18 13:29:39

"Ed Brey" <brey_at_[hidden]> writes:

> Extract is confusing. One problem is that it is deceivingly named.

The name was my suggestion, so I'm going to argue with you a bit about

> It doesn't extract data from the variant at all, but rather provides
> type-specific access to data that still resides in the variant.

"Provides type-specific access to data that still resides in the
variant" is a mouthful, but I'm still not sure what it means. How is
it different from extracting the data?

> It is not clear from the name or the documentation that this would
> be bad:
> variant<int>* v = new variant<int>; extract<int> i(*v); delete v;
> return i;

Ugh. Is it clear from the name that this would be bad?

std::back_insert_iterator<std::vector<int> > f()
    vector<int> v;
    return back_inserter(v);

If the documentation for extract doesn't say that behavior is
undefined if extraction occurs after the constructor argument is
destroyed, it should. Wouldn't that cover your (rather implausible)

> The area would be helped by renaming extract to access.

How is "access" any clearer? "Access" can plausibly be interpreted as
a noun or a verb in the context of variant, so I don't like it very

BTW, I just realized that a conversion from variant<T> to optional<T>
could be used to do extraction as well. Maybe it would be better to
ditch extract altogether and just use optional?

Dave Abrahams
Boost Consulting

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