News for hackers. Stuff that matters.
Re:Show HN: Python to C++14 transpiler by seivan on Monday January 18, 2016 @03:58AM (#10923350)
Would someone be kind to explain how the transpiler/compiler knows that num of T1 generic(?) type can be used with the <= operator? Or that something the user themselves have to define?

Wouldn't be something like "T1 where T1 is Numeric"?

Thanks!

Re:Show HN: Python to C++14 transpiler by inglor on Monday January 18, 2016 @04:59AM (#10923528)
This is how C++ templates work. They are a form of polymorphism through how you use the object and not based on its type.

If you pass a type that cannot be used with the <= operator it will error in compile time.

Being able to do this is part of why C++ templates are much more powerful than Java/C# generics and why they enable a different (and alternative) form of polymorphism to inheritance and explicit interfaces.

Re:Show HN: Python to C++14 transpiler by seivan on Monday January 18, 2016 @05:28AM (#10923601)
I see. In e.g Swift, you'd have to define before hand that T1 could be used with <= while here I guess it adds in the method for "each" T1 that could be used with it.

I assume this just duplicates the method for each type at compile time instead of at runtime try to figure it out?

Damnit, now I wanna rewrite back to C++.

Re:Show HN: Python to C++14 transpiler by jschwartzi on Monday January 18, 2016 @07:56AM (#10924099)
In C++ it just prints an error message and halts compilation if you try to use a type which doesn't support the semantics of the template function. It does not add functions which are not declared already.
Re:Show HN: Python to C++14 transpiler by aldanor on Monday January 18, 2016 @12:31PM (#10925599)
That's what C++ concepts are for (maybe we'll see them in C++17).
Re:Show HN: Python to C++14 transpiler by morgenkaffee on Monday January 18, 2016 @04:26AM (#10923432)
It is all magic of Clang or GCC. Once you call the template with T1 the C++ compiler will enforce that your passed type supports the <= operator.