GoingNative 2012 to be livestreamed tomorrow - part 2

bearophile bearophileHUGS at lycos.com
Thu Feb 9 17:47:21 PST 2012


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__)) { /*...*/ }


An alternative is to give an else to the template constraints, but the error message is at the bottom of the function, making it not easy to find, so I don't like this syntax:


int spam(T)(T x) if (IsFoo!T || IsBar!T) {
    // ...
} else {
    __ctfeWriteln("'", typeid(T), "' is not Foo or Bar.");
}


If Concepts are a type system for templates, then "Current template code remains valid. Constrained and "traditional" templates must interoperate" means "gradual typing", or "optional typing" (see recent Racket Scheme).


Slide 37, "Concepts for the STL (N3351)": how many of them are already in Phobos? Are the missing ones needed/useful for Phobos?


This is Slide 39 and 40 are quite nice:

template<InputIterator Iter, Predicate<ValueType<Iter>> Pred>
bool all_of(Iter first, Iter last, Pred pred);

std::find_if():
template<InputIterator Iter, Predicate<ValueType<Iter>> Pred>
Iter find_if(Iter first, Iter last, Pred pred);


Template aliases seem nice, not to save a bit of code to avoid defining another template, but to allow deducibility as explained here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1449.pdf

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

In the "Panel: Ask Us Anything!" why didn't Andrei comment about the experience of compile-time function execution of D :-)


Later I'll discuss some bits from the talk "Clang - Defending C++ from Murphy's Million Monkeys" in the main D newsgroup because it contains some things more directly relevant for D and its compiler.

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list