April 15, 2015 Type trait alias parameters being either a string or a type | ||||
---|---|---|---|---|
| ||||
As a follow up to http://forum.dlang.org/thread/waxtzdemkuzvqdwilulj@forum.dlang.org#post-waxtzdemkuzvqdwilulj:40forum.dlang.org I'm trying to create a type trait isIndexableBy at https://github.com/nordlow/justd/blob/isIndexableBy-problem/typecons_ex.d DMD complains typecons_ex.d(78,30): Error: template instance isUnsigned!("I") does not match template declaration isUnsigned(T) typecons_ex.d(79,30): Error: template instance isIndex_!("I") does not match template declaration isIndex_(I) typecons_ex.d(91,35): Error: template instance typecons_ex.isIndexType!("I") error instantiating typecons_ex.d(95,19): instantiated from here: isIndexableBy!(int[], "I") typecons_ex.d(96,19): Error: template instance isIndexableBy!(int[3], ubyte) does not match template declaration isIndexableBy(R, alias I) typecons_ex.d(183,20): Error: template typecons_ex.indexedBy cannot deduce function from argument types !(ubyte)(int[3]), candidates are: typecons_ex.d(156,6): typecons_ex.indexedBy(alias I, R)(R range) if (isIndexableBy!(R, I)) How do I make the call isUnsigned!I return false instead of error when I is a CT string literal? Is my design sane ("D-ish")? |
April 15, 2015 Re: Type trait alias parameters being either a string or a type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Wednesday, 15 April 2015 at 08:42:31 UTC, Nordlöw wrote: > As a follow up to > > http://forum.dlang.org/thread/waxtzdemkuzvqdwilulj@forum.dlang.org#post-waxtzdemkuzvqdwilulj:40forum.dlang.org > > I'm trying to create a type trait isIndexableBy at > > https://github.com/nordlow/justd/blob/isIndexableBy-problem/typecons_ex.d > > DMD complains > > typecons_ex.d(78,30): Error: template instance isUnsigned!("I") does not match template declaration isUnsigned(T) > typecons_ex.d(79,30): Error: template instance isIndex_!("I") does not match template declaration isIndex_(I) > typecons_ex.d(91,35): Error: template instance typecons_ex.isIndexType!("I") error instantiating > typecons_ex.d(95,19): instantiated from here: isIndexableBy!(int[], "I") > typecons_ex.d(96,19): Error: template instance isIndexableBy!(int[3], ubyte) does not match template declaration isIndexableBy(R, alias I) > typecons_ex.d(183,20): Error: template typecons_ex.indexedBy cannot deduce function from argument types !(ubyte)(int[3]), candidates are: > typecons_ex.d(156,6): typecons_ex.indexedBy(alias I, R)(R range) if (isIndexableBy!(R, I)) > > How do I make the call isUnsigned!I return false instead of error when I is a CT string literal? > > Is my design sane ("D-ish")? I managed to make it all work at https://github.com/nordlow/justd/blob/master/typecons_ex.d#L114 by using two separate definitions of IndexedBy. Not pretty but works for now. See http://forum.dlang.org/thread/waxtzdemkuzvqdwilulj@forum.dlang.org#post-cirmlonzdhcryinyeyap:40forum.dlang.org for follow-up posts. |
Copyright © 1999-2021 by the D Language Foundation