On Saturday, 18 January 2014 at 00:32:53 UTC, Stanislav Blinov
wrote:
On Saturday, 18 January 2014 at 00:23:14 UTC, Adam D. Ruppe
wrote:
Templates automatically infer their attributes based on the
input, so you don't have to specify them there.
If you do a foo!(nothrow_function)(), foo is also nothrow
(unless, of course, it throws!)
This doesn't apply here. I'm not using function as a template
paramter.
That's the whole case here. Suppose I'm writing a template
class that's parametrized by some type, and in my method I want
to call methods of that type. I cannot make any of my functions
nothrow until I am sure the methods I call will not throw, and
the compiler will tell me. And how can I be sure they don't
throw if it's an arbitrary type? I can check it, sure, with
that isNoThrow() template. But how then to use that information
in my own function declaration?
Perhaps using template if statements and pure functions. A little
like how I implemented some of Dvorm's[0] utility functions. That
way it can execute at compile time. You can pass the type to it
and check any method you would call if its nothrow or not via
traits.
That way you can have two declarations but with one being
opposite of the if.
[0]
https://github.com/rikkimax/Dvorm/blob/master/src/orm/util.d#L31