Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 is currently offline  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?
Previous Topic: CodeEditor syntax support refactored
Next Topic: Building U++ for MinGW32
Goto Forum:
  


Current Time: Thu Apr 18 19:34:17 CEST 2024

Total time taken to generate the page: 0.02157 seconds