Re: How to "extend" built-in types

2012-10-27 Thread Jonathan M Davis
On Saturday, October 27, 2012 12:34:28 simendsjo wrote: > So something like this then? Whatever you need for what you're trying to do. If your example templates test what you need tested, then they should work, though I confess that for something like division, it seems to me to be overkill to c

Re: How to "extend" built-in types

2012-10-27 Thread simendsjo
On Saturday, 27 October 2012 at 10:07:20 UTC, Jonathan M Davis wrote: On Saturday, October 27, 2012 11:58:57 simendsjo wrote: The thing is that I often doesn't really care about the type, only that it exposes certain properties. Then create a template constraint (or eponymous template to use

Re: How to "extend" built-in types

2012-10-27 Thread Jonathan M Davis
On Saturday, October 27, 2012 11:58:57 simendsjo wrote: > The thing is that I often doesn't really care about the type, > only that it exposes certain properties. Then create a template constraint (or eponymous template to use in a template constraint) which tests for those properties. That's exa

Re: How to "extend" built-in types

2012-10-27 Thread simendsjo
On Friday, 26 October 2012 at 16:32:29 UTC, Jonathan M Davis wrote: On Friday, October 26, 2012 15:55:34 simendsjo wrote: So.. What do I need to implement for a struct to be a valid built-in type? All valid properties (min, max etc) and operators for that type? So, you want stuff like isFloat

Re: How to "extend" built-in types

2012-10-26 Thread Jonathan M Davis
On Friday, October 26, 2012 15:55:34 simendsjo wrote: > So.. What do I need to implement for a struct to be a valid > built-in type? > All valid properties (min, max etc) and operators for that type? So, you want stuff like isFloatingPoint and isNumeric to return true for a user-defined struct? T

Re: How to "extend" built-in types

2012-10-26 Thread Dan
On Friday, 26 October 2012 at 13:55:35 UTC, simendsjo wrote: Not sure if this is a bug or intended behavior: ... So.. What do I need to implement for a struct to be a valid built-in type? All valid properties (min, max etc) and operators for that type? I am looking for something similar. I ende

How to "extend" built-in types

2012-10-26 Thread simendsjo
Not sure if this is a bug or intended behavior: import std.traits; struct S { int i; T opCast(T)() if(isFloatingPoint!T) { return cast(T)i; } } template myIsFloatingPoint(T) { enum myIsFloatingPoint = isFloatingPoint!T || __traits(compiles, { cast(real)T.in