[Issue 11658] implicit conversion of associative array literal to (typesafe variadic) tuple array

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Dec 1 13:46:10 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11658


Igor Stepanov <wazar.leollone at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wazar.leollone at yahoo.com


--- Comment #1 from Igor Stepanov <wazar.leollone at yahoo.com> 2013-12-01 13:46:07 PST ---
IMO, it's more then need to AA and less then need to user types.
First AA literal usage that I see is an JSONValue initialization:

JSONValue var = [
  "Key1":42L,
  "Key2":"foo",
  "Key3":[1, "bar", 12.7]
];

I suggest another way to implement this feature.
1. declare in in object two structs:

struct AssociativeArrayLiteral(T...)
{
    //void
}

struct ArrayLiteral(T...)
{
    //void
}

2. Allow converting [a:b, c:d] to AssociativeArrayLiteral!(a, b, c, d)() and
[a, b, c, d] to ArrayLiteral!(a, b, c)

3. User can implement his type like the following:

struct MyJSON
{
    this(T)(T var)
    {
        static if(is(T : AssociativeArrayLiteral!TL, TL...))
        {
            pragma(msg, TL.stringof); //TL is an expanded AA-literal tuple
        }
        else
        {
            static assert(0);
        }
    }
}

4. By default [a:[b,c,d]] should converts to associative array with key `a` and
D-array value [b,c,d], but if outer literal boxed to AssociativeArrayLiteral,
inner literal should be boxed to ArrayLiteral without attempting to represent
it as standart D array, even if it possible. If a user wants to control parsing
of outer literal manually then only he knows how to parse inner literals.

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


More information about the Digitalmars-d-bugs mailing list