On Fri, Mar 15, 2019 at 04:29:22PM -0700, Ali Çehreli via Digitalmars-d-learn
wrote:
> On 03/15/2019 03:48 PM, H. S. Teoh wrote:
[...]
> > Ali's example was unfortunately deceptively formatted.
>
> My editor did that. :)
This is why I don't trust auto-formatters. ;-)
> On my work computer,
On 03/15/2019 03:48 PM, H. S. Teoh wrote:
On Fri, Mar 15, 2019 at 10:30:41PM +, eXodiquas via Digitalmars-d-learn
wrote:
On Friday, 15 March 2019 at 21:46:50 UTC, Ali Çehreli wrote:
[...]
Or use template constraints:
struct Vector {
Vector opBinary(string op)(Vector rhs)
if (op
On Fri, Mar 15, 2019 at 10:30:41PM +, eXodiquas via Digitalmars-d-learn
wrote:
> On Friday, 15 March 2019 at 21:46:50 UTC, Ali Çehreli wrote:
[...]
> > Or use template constraints:
> >
> > struct Vector {
> > Vector opBinary(string op)(Vector rhs)
> > if (op == "+") {
> > return
On Fri, Mar 15, 2019 at 09:35:12PM +, eXodiquas via Digitalmars-d-learn
wrote:
[...]
> Vector opBinary(string op)(Vector rhs)
> {
> static if (op == "+") return Vector(this.x + rhs.x, this.y + rhs.y);
> else static if (op == "-") return Vector(this.x - rhs.x, this.y -
> rhs.y);
> }
>
16.03.2019 1:30, eXodiquas пишет:
On Friday, 15 March 2019 at 21:46:50 UTC, Ali Çehreli wrote:
On 03/15/2019 02:43 PM, Sebastiaan Koppe wrote:
On Friday, 15 March 2019 at 21:35:12 UTC, eXodiquas wrote:
Is there any way to achive this behaivour with D2?
Yep. Just make the return type in the
On Friday, 15 March 2019 at 21:46:50 UTC, Ali Çehreli wrote:
On 03/15/2019 02:43 PM, Sebastiaan Koppe wrote:
On Friday, 15 March 2019 at 21:35:12 UTC, eXodiquas wrote:
Is there any way to achive this behaivour with D2?
Yep. Just make the return type in the function declaration
`auto`. You
On 03/15/2019 02:43 PM, Sebastiaan Koppe wrote:
On Friday, 15 March 2019 at 21:35:12 UTC, eXodiquas wrote:
Is there any way to achive this behaivour with D2?
Yep. Just make the return type in the function declaration `auto`. You
are then free to return a different type in each static branch.
On Friday, 15 March 2019 at 21:35:12 UTC, eXodiquas wrote:
Is there any way to achive this behaivour with D2?
Yep. Just make the return type in the function declaration
`auto`. You are then free to return a different type in each
static branch.
Hi everyone,
i'm currently working on a small physics engine and I thought it
would be a nice feature to overload the operators of my vector
struct so I don't have to make ugly function calls just to add
and "multiply" my vectors. The problem now is that overloading
the addition and
On Monday, 23 January 2017 at 15:15:35 UTC, aberba wrote:
I'm creating a function to authenticate user login. I want to
determine login failure (Boolean) and error message (will be
sent to frontend) but D does have multiple return type
[...]
Yes, MRV can be done with a tuple
auto foo
On Monday, 23 January 2017 at 15:15:35 UTC, aberba wrote:
I'm creating a function to authenticate user login. I want to
determine login failure (Boolean) and error message (will be
sent to frontend) but D does have multiple return type (IMO
could use struct but will make code dirty with too
I'm creating a function to authenticate user login. I want to
determine login failure (Boolean) and error message (will be sent
to frontend) but D does have multiple return type (IMO could use
struct but will make code dirty with too much custom types).
struct Result
{
bool success
class A { ... }
class NonContainer : A { ... }
class Container : A { A[] container; }
class NC1 : NonContainer {}
...
class C1 : Container {}
...
A getO(string info)
{
switch (info)
{
default : return new NonContainer();
case info1: return new
On Sat, 22 Jun 2013 18:58:22 +0200, deed n...@none.none wrote:
class A { ... }
class NonContainer : A { ... }
class Container : A { A[] container; }
class NC1 : NonContainer {}
...
class C1 : Container {}
...
A getO(string info)
{
switch (info)
{
auto o = getO(info3);
if (cast(Container)o != null) { ... }
Thanks Simen.
(Compiler requires !is instead of !=)
On Wednesday, 15 August 2012 at 01:22:41 UTC, Era Scarecrow wrote:
On Wednesday, 15 August 2012 at 00:37:32 UTC, ReneSac wrote:
And my last question of my first post: I can't use auto for
the out values right? An enhancement proposal like this
would be compatible with D?
I would say No.
Thanks, this indeed works. One obvious (when your program
starts to behave weirdly...) down side of this solution: it needs
a different dummy for each optional out value of a function, or
else multiple variables will be modifying the same dummy.
And, of course, a different dummy for each type
On Wednesday, 15 August 2012 at 00:37:32 UTC, ReneSac wrote:
And my last question of my first post: I can't use auto for
the out values right? An enhancement proposal like this would
be compatible with D?
I would say No. Maybe if it was a union, but I don't think
so;.It still needs to
On 08/14/2012 06:22 PM, Era Scarecrow wrote:
On Wednesday, 15 August 2012 at 00:37:32 UTC, ReneSac wrote:
And my last question of my first post: I can't use auto for the
out values right? An enhancement proposal like this would be
compatible with D?
I would say No. Maybe if it was a
On Wednesday, 15 August 2012 at 01:42:11 UTC, Ali Çehreli wrote:
Agreed. The function code must be compiled to use certain
amount of data from the program stack for that particular
parameter. That size of that parameter must be known at compile
time.
The compiler could in theory examine the
On Tuesday, 24 July 2012 at 05:30:49 UTC, Ali Çehreli wrote:
The options that I can think of:
- Return a struct (or a class) where one of the members is not
filled-in
- Similarly, return a tuple
This is awkward, and doesn't look good for performance.
- Use an out parameter, which can
On 08/11/2012 03:48 PM, ReneSac wrote:
On Tuesday, 24 July 2012 at 05:30:49 UTC, Ali Çehreli wrote:
- Use an out parameter, which can have a default lvalue:
int g_default_param;
void foo(ref int i = g_default_param)
{
if (i == g_param) {
// The caller is not interested in 'i'
} else {
There is no compiler bug. You cannot pass immutable/rvalue by reference
to mutable.
On Tuesday, 24 July 2012 at 03:25:55 UTC, ReneSac wrote:
Do I really have to duplicate the function, in order to achieve
this?
In a nutshell, yes. Or else resort to bizarre sorcery such as
may rot the very heart from one's chest (or template ninjitsu,
whatever). But is it really so
Am 24.07.2012 05:25, schrieb ReneSac:
I whish there was:
auto foo() {
return Tuple!(foo, bar, 1, new Custum());
}
void main() {
auto (s1, s2, i, c) = foo();
}
On Tuesday, 24 July 2012 at 03:25:55 UTC, ReneSac wrote:
How I can return multiple values in D, but one of them being
optional?
One of the ways to to it is to return a tuple with your
arguments, where the last item of the tuple is a Nullable of the
optional element:
import std.stdio,
On Tuesday, 24 July 2012 at 08:56:21 UTC, David wrote:
Am 24.07.2012 05:25, schrieb ReneSac:
I whish there was:
auto foo() {
return Tuple!(foo, bar, 1, new Custum());
}
void main() {
auto (s1, s2, i, c) = foo();
}
I think the main blocker to something like that right now is the
It seems forum.dlang.org hides my first answer, I don't know why:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learnarticle_id=37708
Bye,
bearophile
How I can return multiple values in D, but one of them being
optional? I tried the 'out' hack to achieve multiple return
values, but it didn't accepted a default argument: it needed a
lvalue in the calling function.
In Lua, for example, one can do:
function foo(input)
-- calculations
On 07/23/2012 08:25 PM, ReneSac wrote:
How I can return multiple values in D, but one of them being optional? I
tried the 'out' hack to achieve multiple return values, but it didn't
accepted a default argument: it needed a lvalue in the calling function.
Like in C and C++, functions in D can
thanks you all, it works.
last thing, I have this
Tuple!(int,int,int)(1, 2, 3)
how can I use the return values individual?
to be more clear if I rturn tuple(a, b, c) can I write in the code
void main() {
//call the function here
writeln(a);
}
%u:
how can I use the return values individual?
One of the simpler ways is to think of a tuple as an array, and use
sometuple[0] to take its first item, etc. But your tuple indexes need to be
compile-time constants.
Bye,
bearophile
I have function which have more than one return, and the code compile and run
but it gives rong result -I guess-, so i use tuple but the compiler can't
return tuple.
how can I return values?
why I can't return tuple?
%u:
I have function which have more than one return, and the code compile and run
but it gives rong result -I guess-, so i use tuple but the compiler can't
return tuple.
how can I return values?
why I can't return tuple?
Currently in D there are two ways to return multiple values from a
On 2011-04-20 01:35:46 +0300, %u said:
I have function which have more than one return, and the code compile and run
but it gives rong result -I guess-, so i use tuple but the compiler can't
return tuple.
how can I return values?
why I can't return tuple?
In D, tuple is not built in type, it
35 matches
Mail list logo