Changeset 1541
- Timestamp:
- 05/23/10 01:07:22 (15 years ago)
- Files:
-
- trunk/phobos/std/traits.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/traits.d
r1540 r1541 1529 1529 template checkSTC() 1530 1530 { 1531 1531 // Note the order of arguments. The convertion order Lwr -> Upr is 1532 1532 // correct since Upr should be semantically 'narrower' than Lwr. 1533 1533 enum ok = isStorageClassImplicitlyConvertible!(Lwr, Upr); 1534 1534 } 1535 1535 /* 1536 1536 * Check for function attributes: 1537 1537 * - require exact match for ref and @property 1538 1538 * - overrider can add pure and nothrow, but can't remove them 1539 * - trust: ?1539 * - @safe and @trusted are covariant with each other, unremovable 1540 1540 */ 1541 1541 template checkAttributes() 1542 1542 { 1543 1543 alias FunctionAttribute FA; 1544 1544 enum uprAtts = functionAttributes!(Upr); 1545 1545 enum lwrAtts = functionAttributes!(Lwr); 1546 1546 // 1547 1547 enum WANT_EXACT = FA.REF | FA.PROPERTY; 1548 enum TRUST= FA.SAFE | FA.TRUSTED;1548 enum SAFETY = FA.SAFE | FA.TRUSTED; 1549 1549 enum ok = 1550 ( (uprAtts & WANT_EXACT) ==(lwrAtts & WANT_EXACT)) &&1551 ( (uprAtts & FA.PURE ) >=(lwrAtts & FA.PURE )) &&1552 ( (uprAtts & FA.NOTHROW) >=(lwrAtts & FA.NOTHROW)) &&1553 ( (uprAtts & TRUST ) >= (lwrAtts & TRUST )) ; // XXX1550 ( (uprAtts & WANT_EXACT) == (lwrAtts & WANT_EXACT)) && 1551 ( (uprAtts & FA.PURE ) >= (lwrAtts & FA.PURE )) && 1552 ( (uprAtts & FA.NOTHROW) >= (lwrAtts & FA.NOTHROW)) && 1553 (!!(uprAtts & SAFETY ) >= !!(lwrAtts & SAFETY )) ; 1554 1554 } 1555 1555 /* 1556 1556 * Check for return type: usual implicit convertion. 1557 1557 */ 1558 1558 template checkReturnType() 1559 1559 { 1560 1560 enum ok = is(ReturnType!(Upr) : ReturnType!(Lwr)); 1561 1561 } 1562 1562 /* 1563 1563 * Check for parameters: … … 1636 1636 static assert(! isCovariantWith!(BaseB.test, DerivB_1.test)); 1637 1637 static assert(! isCovariantWith!(BaseB.test, DerivB_2.test)); 1638 1638 static assert(! isCovariantWith!(BaseB.test, DerivB_3.test)); 1639 1639 1640 1640 // function storage class 1641 1641 interface BaseC { void test() ; } 1642 1642 interface DerivC_1 : BaseC { override void test() const; } 1643 1643 static assert(isCovariantWith!(DerivC_1.test, BaseC.test)); 1644 1644 static assert(! isCovariantWith!(BaseC.test, DerivC_1.test)); 1645 1645 1646 // trust1646 // increasing safety 1647 1647 interface BaseE { void test() ; } 1648 1648 interface DerivE_1 : BaseE { override void test() @safe ; } 1649 1649 interface DerivE_2 : BaseE { override void test() @trusted; } 1650 1650 static assert(isCovariantWith!(DerivE_1.test, BaseE.test)); 1651 1651 static assert(isCovariantWith!(DerivE_2.test, BaseE.test)); 1652 1652 static assert(! isCovariantWith!(BaseE.test, DerivE_1.test)); 1653 1653 static assert(! isCovariantWith!(BaseE.test, DerivE_2.test)); 1654 1655 // @safe and @trusted 1656 interface BaseF 1657 { 1658 void test1() @safe; 1659 void test2() @trusted; 1660 } 1661 interface DerivF : BaseF 1662 { 1663 override void test1() @trusted; 1664 override void test2() @safe; 1665 } 1666 static assert(isCovariantWith!(DerivF.test1, BaseF.test1)); 1667 static assert(isCovariantWith!(DerivF.test2, BaseF.test2)); 1654 1668 } 1655 1669 1656 1670 1657 1671 //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::// 1658 1672 // isSomething 1659 1673 //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::// 1660 1674 1661 1675 /** 1662 1676 * Detect whether T is a built-in integral type. Types $(D bool), $(D 1663 1677 * char), $(D wchar), and $(D dchar) are not considered integral.
