Home » Developing U++ » U++ Developers corner » One vs std::experimental::optional
One vs std::experimental::optional [message #43327] |
Mon, 30 June 2014 21:03 |
piotr5
Messages: 107 Registered: November 2005
|
Experienced Member |
|
|
I discovered an interesting discussion about classes storing optional values. so I thought I might try the same problem-case with Upp::One
struct A
{
constexpr A(int &x) : ref(x) {}
int &ref;
};
int toptional()
{
int n1 = 0, n2 = 0;
One<A> opt(new A(n1));
A* a=new A(n2);
opt=a;
opt->ref = 1;
Cout() << n1 << " " << n2 << EOL;
}
the result is "0 1" as it should be. since upp isn't using a union, and it only works with values on heap (thereby being useless for constexpr values because of the required destructor), it's quite safe to use. I wonder why stdc++ wont implement it that way. what's the use of constexpr optional values anyway?
unfortunately I don't quite understand the things posted in above link. why isn't 1<2?
|
|
|
Goto Forum:
Current Time: Fri Nov 01 00:03:08 CET 2024
Total time taken to generate the page: 0.00602 seconds
|