www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Homework help, guys!

reply "hunt" <jaeyoep gmail.com> writes:
Hello, guys. It is weird to ask about my homework here, but I 
haven't gotten a proper answer yet. It's about D feature...maybe..

http://dpaste.dzfl.pl/905d6ad7

Question is that "Investigate how D allows you to defend your 
definition of Map so that it may be used only with a type of key 
that is comparable, and place this defense in your solution."

Please leave your comments here. Thank you so much.
Aug 01 2013
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 08/02/2013 01:34 AM, hunt wrote:
 Hello, guys. It is weird to ask about my homework here, but I haven't
 gotten a proper answer yet. It's about D feature...maybe..

 http://dpaste.dzfl.pl/905d6ad7

 Question is that "Investigate how D allows you to defend your definition
 of Map so that it may be used only with a type of key that is
 comparable, and place this defense in your solution."

 Please leave your comments here. Thank you so much.
This should get you started: http://dlang.org/concepts.html http://dlang.org/traits.html#compiles
Aug 01 2013
parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Thursday, 1 August 2013 at 23:48:33 UTC, Timon Gehr wrote:
 On 08/02/2013 01:34 AM, hunt wrote:
 Hello, guys. It is weird to ask about my homework here, but I 
 haven't
 gotten a proper answer yet. It's about D feature...maybe..

 http://dpaste.dzfl.pl/905d6ad7

 Question is that "Investigate how D allows you to defend your 
 definition
 of Map so that it may be used only with a type of key that is
 comparable, and place this defense in your solution."

 Please leave your comments here. Thank you so much.
This should get you started: http://dlang.org/concepts.html http://dlang.org/traits.html#compiles
Also, say hello to the most esoteric expression I can think of: D's "is" expression http://dlang.org/expression.html#IsExpression
Aug 01 2013
parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Thursday, 1 August 2013 at 23:57:47 UTC, John Colvin wrote:
 On Thursday, 1 August 2013 at 23:48:33 UTC, Timon Gehr wrote:
 On 08/02/2013 01:34 AM, hunt wrote:
 Hello, guys. It is weird to ask about my homework here, but I 
 haven't
 gotten a proper answer yet. It's about D feature...maybe..

 http://dpaste.dzfl.pl/905d6ad7

 Question is that "Investigate how D allows you to defend your 
 definition
 of Map so that it may be used only with a type of key that is
 comparable, and place this defense in your solution."

 Please leave your comments here. Thank you so much.
This should get you started: http://dlang.org/concepts.html http://dlang.org/traits.html#compiles
Also, say hello to the most esoteric expression I can think of: D's "is" expression http://dlang.org/expression.html#IsExpression
http://dpaste.dzfl.pl/f3d7c828 //Via constraits //This will do a template mismatch struct Map1(T) if (is(typeof(T.init < T.init))) { //Who cares } //Via (explicit) compilation errors struct Map2(T) { static assert (is(typeof(T.init < T.init)), "Error, " ~ T ~ " is not comparable."); } void main() { struct S {} //Not comparable assert( is(Map1!int)); assert(!is(Map1!S)); assert( is(Map2!int)); assert(!is(Map2!S)); }
Aug 02 2013