UDAs - Restrict to User Defined Types?

Jonas Drewsen nospam4321 at hotmail.com
Fri Nov 9 01:09:03 PST 2012


On Friday, 9 November 2012 at 07:29:28 UTC, Jonathan M Davis 
wrote:
> On Friday, November 09, 2012 08:21:38 Jacob Carlborg wrote:
>> On 2012-11-09 07:20, H. S. Teoh wrote:
>> > Well, unittests are a runtime check, and they don't 
>> > *guarantee*
>> > anything. (One could, in theory, write a pathological 
>> > pseudo-range that
>> > passes basic unittests but fail to behave like a range in 
>> > some obscure
>> > corner case. Transient ranges would fall under that 
>> > category, should we
>> > decide not to admit them as valid ranges. :-))
>> > 
>> > But of course that's just splitting hairs.
>> 
>> But since we do have a language with static typing we can at 
>> least do
>> our best to try at catch as many errors as possible at compile 
>> time. We
>> don't want to end up as a dynamic language and testing for 
>> types in the
>> unit tests.
>
> But the types are already tested by the templat constraints and 
> the fact that
> they compile at all. It's the functions' runtime behaviors that 
> can't be
> tested, and no language can really test that at compile time, 
> whereas unit
> test _do_ test the runtime behavior. So, you get both static 
> and dynamic
> checks.

I guess some runtime behavior could actually be tested at compile 
time using CTFE?

int doubleMe(int a) { return 2 * a }
static test = doubleMe(3);
static assert(test == 6);

But maybe that is splittin' hares as well :)

/Jonas





More information about the Digitalmars-d mailing list