How to know if opSlice is defined for a type (including built-in types)?

chardetm via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 20 02:58:15 PST 2016


On Wednesday, 20 January 2016 at 10:44:36 UTC, Rikki Cattermole 
wrote:
>
> template CanSlice(T) {
> 	enum CanSlice = __traits(compiles, {T t; auto v = t[0 .. 1];}) 
> || __traits(compiles, {T t; auto v = t.opSlice();});
> }
>
> Should work.

Thanks it works just fine!


More information about the Digitalmars-d-learn mailing list