Boost logo

Boost :

Subject: Re: [boost] [variant] assign and access the assigned value simultaneously
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2014-03-19 03:13:56


2014-03-14 10:22 GMT+04:00 feverzsj <feverzsj_at_[hidden]>:
<...>

> why not supply a interface like:
>
> Val& v = var.assign(val);
>
> for simplity, and the unnecessary "get" is also elimited.
>

Such interface is not common for C++. Most programmers are used to the
following:

class_name& class_name::operator=(const class_name&);
or
class_name& class_name::operator=(const class_internal&);

While you propose to implement `class_internal& class_name::operator=(const
class_internal&);`
This may be surprising for some users:

boost::variant<Val,...> var;
boost::variant<Val,...>& var2 = var = val;

Code from the example above will have different behavior on different
compilers (GCC won't compile it, MSVC will compile it but &var2 != &var1).
This does not look good.

-- 
Best regards,
Antony Polukhin

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