http://d.puremagic.com/issues/show_bug.cgi?id=596
Simen Kjaeraas <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #11 from Simen Kjaeraas <[email protected]> 2013-03-03 10:16:01 PST --- The problem of your proposed pattern matching is that there is not necessarily a simple correlation between constructor parameters and runtime values. For instance, for this struct declaration: struct Foo { int n; this( int a, int b ) { n = a * b; } } , Foo( 12, void ) just doesn't make any sense. For tuples however, this works: struct DontCare { bool opEquals( T )( T other ) const { return true; } } enum DontCare dontCare = DontCare( ); unittest { import std.typecons : Tuple, tuple; static class A {} auto a = tuple( 12, "foo" ); assert( a == tuple( 12, dontCare ) ); assert( a == tuple( dontCare, "foo" ) ); assert( a != tuple( 42, dontCare ) ); assert( a != tuple( dontCare, "bar" ) ); assert( tuple( 12, dontCare ) == a ); assert( tuple( dontCare, "foo" ) == a ); assert( tuple( 42, dontCare ) != a ); assert( tuple( dontCare, "bar" ) != a ); auto aa = new A( ); auto b = tuple( 1.5f, aa ); assert( tuple( 1.5f, dontCare ) == b ); assert( tuple( dontCare, aa ) == b ); assert( tuple( 3.5f, dontCare ) != b ); assert( tuple( dontCare, cast(A)null ) != b ); assert( b == tuple( 1.5f, dontCare ) ); assert( b == tuple( dontCare, aa ) ); assert( b != tuple( 3.5f, dontCare ) ); assert( b != tuple( dontCare, cast(A)null ) ); } This would allow switch statements like this: switch (myTuple) { case tuple( 3, dontCare ): // A break; case tuple( dontCare, "foo" ): // B break; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
