Changeset 491
- Timestamp:
- 01/09/11 06:39:21 (14 years ago)
- Files:
-
- trunk/import/object.di (modified) (1 diff)
- trunk/src/object_.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/import/object.di
r488 r491 402 402 { 403 403 return &opApply; 404 404 } 405 405 406 406 Value get(Key key, lazy Value defaultValue) 407 407 { 408 408 auto r = key in *cast(Value[Key]*)(&p); 409 409 return r ? *r : defaultValue; 410 410 } 411 411 412 @property Value[Key] dup() 413 { 414 Value[Key] result; 415 foreach (k, v; this) 412 static if (is(typeof({ Value[Key] r; r[Key.init] = Value.init; }()))) 413 @property Value[Key] dup() 416 414 { 417 result[k] = v; 415 Value[Key] result; 416 foreach (k, v; this) 417 { 418 result[k] = v; 419 } 420 return result; 418 421 } 419 return result;420 }421 422 } 422 423 423 424 unittest 424 425 { 425 426 auto a = [ 1:"one", 2:"two", 3:"three" ]; 426 427 auto b = a.dup; 427 428 assert(b == [ 1:"one", 2:"two", 3:"three" ]); 428 429 } 429 430 430 431 void clear(T)(T obj) if (is(T == class)) trunk/src/object_.d
r488 r491 2448 2448 { 2449 2449 return &opApply; 2450 2450 } 2451 2451 2452 2452 Value get(Key key, lazy Value defaultValue) 2453 2453 { 2454 2454 auto p = key in *cast(Value[Key]*)(&p); 2455 2455 return p ? *p : defaultValue; 2456 2456 } 2457 2457 2458 @property Value[Key] dup() 2459 { 2460 Value[Key] result; 2461 foreach (k, v; this) 2462 { 2463 result[k] = v; 2464 } 2465 return result; 2466 } 2458 static if (is(typeof({ Value[Key] r; r[Key.init] = Value.init; }()))) 2459 @property Value[Key] dup() 2460 { 2461 Value[Key] result; 2462 foreach (k, v; this) 2463 { 2464 result[k] = v; 2465 } 2466 return result; 2467 } 2467 2468 } 2468 2469 2469 2470 unittest 2470 2471 { 2471 2472 auto a = [ 1:"one", 2:"two", 3:"three" ]; 2472 2473 auto b = a.dup; 2473 2474 assert(b == [ 1:"one", 2:"two", 3:"three" ]); 2474 2475 } 2475 2476 2476 2477 void clear(T)(T obj) if (is(T == class))
