digitalmars.D.learn - function returning a tuple
- WhatMeWorry (20/20) Apr 08 2016 This might be a very simple fix, but I've been fighting this for
- =?UTF-8?Q?Ali_=c3=87ehreli?= (17/36) Apr 08 2016 Collision is a variable. Did you mean
- jmh530 (4/5) Apr 08 2016 I was getting that same error recently, but I forgot what was
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.
Apr 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
Apr 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?
Apr 08 2016