www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2150] New: cannot get values from const variant

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2150

           Summary: cannot get values from const variant
           Product: D
           Version: 2.014
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: andrei metalanguage.com
        ReportedBy: blprice61 yahoo.com


Unable to retrieve a value via get or coerce from a const variant.  Also a
related problem, unable to create a mutable copy of a const variant.  The
following code illustrates the issue:

class Wrapper 
{
        private:
        Variant m_value;

        public:
version(test_one) {     
        this(const Variant value)
        {
//              m_value = value; // fails with same error as below              
                m_value = Variant(value); 
// Error message: static assert  "Cannot store a const(VariantN!(maxSize)) in a
// VariantN!(maxSize)"
        }
} else version(test_two) {
        this(Variant value)
        {
                m_value = value;
        }
}
        int getInt() const
        {
//              return m_value.get!(int)();  // fails with same error as below
                return m_value.get!(const int)(); 
// Error message: this.m_value.get can only be called on a mutable object,
// not const(VariantN!(maxSize))
        }
}

unittest {
        int expected = 5;
        auto v = Variant(expected);
        Wrapper w = new Wrapper(v);
        int result = w.getInt();
        assert(expected == result);
}

Attempts to cast away the const'ness of the variant and develop a workaround
have failed with errors such as: cannot convert const(int) to const(int)...


-- 
Jun 14 2008
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2150


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




--- Comment #1 from Andrei Alexandrescu <andrei metalanguage.com>  2009-08-27
13:08:53 PDT ---
Fixed in the next release. (I'm still unhappy about a few details about Variant
and const.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 27 2009