Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does D solve this issue with return types?

Tags:

syntax

function

d

C++11 introduced a new syntax for function declaration,

auto func(T rhs, U lhs) -> V

This was to solve some problems that appeared in the old C++ standard with function templates. Read this short Wikipedia article section for details about the problem:
> http://en.wikipedia.org/wiki/C%2B%2B11#Alternative_function_syntax

My question is, does D confront with the same problem? If so, how does it fix it (if at all)?

like image 758
Paul Manta Avatar asked Nov 07 '11 10:11

Paul Manta


People also ask

What is d solve?

DSolve can solve ordinary differential equations (ODEs), partial differential equations (PDEs), differential algebraic equations (DAEs), delay differential equations (DDEs), integral equations, integro-differential equations, and hybrid differential equations.

How do you solve differential equations in Python?

Differential equations are solved in Python with the Scipy. integrate package using function odeint or solve_ivp. t: Time points at which the solution should be reported. Additional internal points are often calculated to maintain accuracy of the solution but are not reported.


1 Answers

In D, the compiler can deduce the return type for you. So there's no need to have the -> V syntax.

auto func(T, U)(T lhs, U rhs) { return lhs + rhs; }

or if you want to be more specific (but it's better to let the compiler figure out the type with auto!)

typeof(T.init + U.init) func(T, U)(T lhs, U rhs) { return lhs + rhs; }

Like C++, you cannot use typeof(lhs + rhs) in that place.

like image 194
kennytm Avatar answered Sep 28 '22 17:09

kennytm