On 02/10/2012 08:17 AM, Jacob Carlborg wrote:
On 2012-02-10 02:47, bearophile wrote:
Some more comments about the conference.

--------------------------

About "Variadic Templates are Funadic" by Andrei Alexandrescu fun talk:

I have had to see it at only 1-1.1X speed, to understand the language.

I can't see the laser spot in the video :-(

Thank you to Walter for designing D varidic templates in a simpler
way. C++11 variadic templates look too much complex and
over-engineered (example: the lockstep expansion seems a bit crazy).

Slide 21: I didn't know that default is OK as first switch case too :-)

Even the questions&answers part of this talk was interesting enough.

------------------

About Bjarne Stroustrup and Andrew Sutton "A Concept Design for C++":

Regarding this code in Slide 12:

template<Number Num> Num gsqrt(Num);
gsqrt(2); // fine
gsqrt("Silly!"); // error: char* is not a Number


In D template constraints have two (or more) different usages:
1) To just remove a template from the pool of the usable ones;
2) In other situations only one template is present, and its
constraints are a way to give it some static typing. In this case I'd
like better error messages.


Once this patch is applied:
https://github.com/D-Programming-Language/dmd/pull/692

you are able to write something like this, that isn't exceptionally
nice looking, but it's useful (it's going to make Phobos code a bit
more hairy, but the user is going to see some better error messages):


template IsNumberWithError(T, string file, int line) {
enum bool IsNumberWithError = is( ...
static if (!IsNumberWithError)
__ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number.");
}

double gsqrt(T)(T x) if (IsNumberWithError!(T, __FILE__, __LINE__)) {
/*...*/ }

Wouldn't this be possible:


template IsNumberWithError(T, string file = __FILE__, int line =
__LINE__) {
enum bool IsNumberWithError = is( ...
static if (!IsNumberWithError)
__ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number.");
}

double gsqrt(T)(T x) if (IsNumberWithError!(T)) { /*...*/ }

__FILE__ and __LINE__ would be picked up from the "calling" point and
not the declaration point of IsNumberWithError. We already have this in
some cases.


Unfortunately, they would point to the template constraint. But I think it would be a quite useful enhancement to pick up __FILE__ and __LINE__ at template instantiation point for the template constraint.

Reply via email to