www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7356] New: Implement KeyType, ValueType for hashes in std.traits

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

           Summary: Implement KeyType, ValueType for hashes in std.traits
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2012-01-23
22:50:34 PST ---
I've had a use-case for these but they were not in std.traits, so here's an
implementation:

import std.traits;

template KeyType(AA)
   if (isAssociativeArray!AA)
{
   static if (is(AA V : V[K], K))
   {
       alias K KeyType;
   }
}

template ValueType(AA)
   if (isAssociativeArray!AA)
{
   static if (is(AA V : V[U], U))
   {
       alias V ValueType;
   }
}

If I get an OK I can make a pull for this (with documentation).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 23 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7356



--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2012-01-24 06:05:29 PST ---
I think the type-deduction template names should be 'KeyTypeOf' and
'ValueTypeOf'.

It is consistent with FunctionTypeOf and StringTypeOf (it's undocumented).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7356



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2012-01-24
06:38:05 PST ---
I've based it on ReturnType. There's a mix of these names, such as:
FunctionTypeOf
FieldTypeTuple

Some have "Of", others don't. I don't see what "Of" adds, except verbosity.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7356


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com


--- Comment #3 from Jonathan M Davis <jmdavisProg gmx.com> 2012-01-24 08:05:06
PST ---
I wouldn't expect the Of on them. It's awkward in comparison IMHO. I don't know
why FunctionTypeOf and StringTypeOf have Of on them. But if Of is both used and
not used (as appears to be the case), then I wouldn't use it - especially when
the cases that _do_ use it are undocumented.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7356


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #4 from bearophile_hugs eml.cc 2012-01-24 10:42:57 PST ---
KeyType and ValueType are good enough names, I used the same in my code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7356



--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2012-01-26 04:07:44 PST ---
(In reply to comment #2)
 Some have "Of", others don't. I don't see what "Of" adds, except verbosity.
IMHO, it comes from the typeof() feature. First of all, and for fairness, `StringTypeOf` is the one that I added into Phobos in the past, so original XXXTypeOf is only FunctionTypeOf. I'm not a native English speaker, but it seems to me that XXXTypeOf!(Y) is more natural than XXXType!(Y). The former looks like a sentence, but latter like a noun. This kind of templates work like meta function, and function name usually contains verb. So I sometimes feel wrong about the latter. And, 'KeyType' and 'ValueType' are often used in user code. I think we should avoid using generic name as the piece of library, as far as possible. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 26 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7356


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

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


--- Comment #6 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2012-04-19
18:57:25 PDT ---
https://github.com/D-Programming-Language/phobos/commit/b64751067f2364d33011e8de736c5f8de6a2f019

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