[Python-ideas] generic code and dependent types

Neal Becker ndbecker2 at gmail.com
Fri Aug 15 15:10:51 CEST 2014


Dennis Brakhane wrote:

> Am 15.08.2014 14:26, schrieb Steven D'Aprano:
>>
>> Let's pretend that this is a Python mailing list, and that some readers
>> aren't familiar with C++ generic syntax :-) What does
>>
>> typedef typeof (int() * float()) my_type;
>>
>> do?
> 
> I think its "whatever type operator*(int a, float b)" returns.
> 
> Or more generally: "whatever type a suitable * operator returns after,
> where suitable means after int and float might or might not have been
> casted into another type so that a matching operator was found"
> 
> So, for example, if there were no operator*(int a, float b), it would
> look if there's at operator*(int a, int b), and if not, operator*(float,
> float) (or vice versa).
> 
> The "advantage" is that you do not need to change your code if the
> meaning of multiplying an int with a float changes.

I really meant more like

typeof (A() * B())

where A and B are 2 types, and A() is a call to the default constructor for A.

For example

ret_t multiply (A a, B b): return a * b

what is ret_t?



More information about the Python-ideas mailing list