Thread overview
function returning a tuple
Apr 08, 2016
WhatMeWorry
Apr 08, 2016
Ali Çehreli
Apr 08, 2016
jmh530
April 08, 2016
This might be a very simple fix, but I've been fighting this for more hours than I care to admit to.


std.typecons says "Tuple of values, for example Tuple!(int, string) is a record that stores an int and a string. Tuple can be used to bundle values together, notably when returning multiple values from a function."


But when I try this in practice with

// typedef std::tuple<GLboolean, Direction, glm::vec2> Collision; // porting C++ to
Tuple!(GLboolean, Direction, vec2) Collision;


Collision CheckCollision(BallObject one, GameObject two) // AABB - Circle collision
{


DMD 2.071.0, keeps returning at the function signature:
Error: functions cannot return a tuple

I've also tried,
alias Collision = AliasSeq!(GLboolean, Direction, vec2);
but same error.

Am I doing anything stupid here?
thanks.






April 08, 2016
On 04/08/2016 01:53 PM, WhatMeWorry wrote:
>
> This might be a very simple fix, but I've been fighting this for more
> hours than I care to admit to.
>
>
> std.typecons says "Tuple of values, for example Tuple!(int, string) is a
> record that stores an int and a string. Tuple can be used to bundle
> values together, notably when returning multiple values from a function."
>
>
> But when I try this in practice with
>
> // typedef std::tuple<GLboolean, Direction, glm::vec2> Collision; //
> porting C++ to
> Tuple!(GLboolean, Direction, vec2) Collision;

Collision is a variable. Did you mean

alias Collision = Tuple!(GLboolean, Direction, vec2);

>
>
> Collision CheckCollision(BallObject one, GameObject two) // AABB -

That won't work because you should have a type instead of Collision (a variable).

> Circle collision
> {
>
>
> DMD 2.071.0, keeps returning at the function signature:
> Error: functions cannot return a tuple
>
> I've also tried,
> alias Collision = AliasSeq!(GLboolean, Direction, vec2);
> but same error.
>
> Am I doing anything stupid here?
> thanks.

And yes, functions can return tuples: :)

import std.typecons;

struct S {
    int i;
}

Tuple!(int, S) foo() {
    return tuple(42, S(43));
}

void main() {
    auto a = foo();
}

Ali


April 08, 2016
On Friday, 8 April 2016 at 20:58:46 UTC, Ali Çehreli wrote:
> And yes, functions can return tuples: :)
>

I was getting that same error recently, but I forgot what was causing it. He mentions AliasSeq above, could the error be referring to compile time argument lists?