Jump to page: 1 2
Thread overview
Return types of the methods of a struct
Jun 19, 2015
Quentin Ladeveze
Jun 19, 2015
Quentin Ladeveze
Jun 19, 2015
Quentin Ladeveze
Jun 19, 2015
Quentin Ladeveze
Jun 19, 2015
Baz
Jun 19, 2015
Daniel Kozák
Jun 19, 2015
Quentin Ladeveze
Jun 19, 2015
Quentin Ladeveze
Jun 19, 2015
ZombineDev
Jun 19, 2015
Quentin Ladeveze
Jun 19, 2015
Baz
Jun 19, 2015
Baz
Jun 19, 2015
Justin Whear
Jun 19, 2015
Quentin Ladeveze
June 19, 2015
Hi,

  I have a struct with some methods int it, let's say

```
struct Example{
   int intValue(){

June 19, 2015
On Friday, 19 June 2015 at 13:12:08 UTC, Quentin Ladeveze wrote:
> Hi,
>
>   I have a struct with some methods int it, let's say
>
> ```
> struct Example{
>    int intValue(){

Hum. How can I delete a post ?
June 19, 2015
On 6/19/15 9:13 AM, Quentin Ladeveze wrote:
> On Friday, 19 June 2015 at 13:12:08 UTC, Quentin Ladeveze wrote:
>> Hi,
>>
>>   I have a struct with some methods int it, let's say
>>
>> ```
>> struct Example{
>>    int intValue(){
>
> Hum. How can I delete a post ?

You can't. The forum is backed by a newsgroup, just post the full corrected version :)

-Steve
June 19, 2015
On Friday, 19 June 2015 at 13:26:03 UTC, Steven Schveighoffer wrote:
> On 6/19/15 9:13 AM, Quentin Ladeveze wrote:
>> On Friday, 19 June 2015 at 13:12:08 UTC, Quentin Ladeveze wrote:
>>> Hi,
>>>
>>>   I have a struct with some methods int it, let's say
>>>
>>> ```
>>> struct Example{
>>>    int intValue(){
>>
>> Hum. How can I delete a post ?
>
> You can't. The forum is backed by a newsgroup, just post the full corrected version :)
>
> -Steve

Thank you :)

Here is th corrected version :

Hi,

  I have a struct with some methods int it, let's say

```
struct Example{
   int a(){
   	  return someValue;
   }

   float b(){
	  return someOtherValue;
   }

   string stringValue(){
      return c;
   }
}

Is there any way to have a asTuple method in this struct that would returns something like :

Tuple!(int, "a", float, "b", string, "c")

and that will contain the values of the methods of the struct ?

Thanks.
June 19, 2015
On 6/19/15 9:27 AM, Quentin Ladeveze wrote:
> On Friday, 19 June 2015 at 13:26:03 UTC, Steven Schveighoffer wrote:
>> On 6/19/15 9:13 AM, Quentin Ladeveze wrote:
>>> On Friday, 19 June 2015 at 13:12:08 UTC, Quentin Ladeveze wrote:
>>>> Hi,
>>>>
>>>>   I have a struct with some methods int it, let's say
>>>>
>>>> ```
>>>> struct Example{
>>>>    int intValue(){
>>>
>>> Hum. How can I delete a post ?
>>
>> You can't. The forum is backed by a newsgroup, just post the full
>> corrected version :)
>>
>> -Steve
>
> Thank you :)
>
> Here is th corrected version :
>
> Hi,
>
>    I have a struct with some methods int it, let's say
>
> ```
> struct Example{
>     int a(){
>           return someValue;
>     }
>
>     float b(){
>        return someOtherValue;
>     }
>
>     string stringValue(){
>        return c;
>     }
> }
>
> Is there any way to have a asTuple method in this struct that would
> returns something like :
>
> Tuple!(int, "a", float, "b", string, "c")
>
> and that will contain the values of the methods of the struct ?

Does this work for you, or is there a further expectation?

auto asTuple() { return Tuple!(int, "a", ...)(a, b, stringValue);}

-Steve
June 19, 2015
On Friday, 19 June 2015 at 13:27:15 UTC, Quentin Ladeveze wrote:
> On Friday, 19 June 2015 at 13:26:03 UTC, Steven Schveighoffer wrote:
>> On 6/19/15 9:13 AM, Quentin Ladeveze wrote:
>>> [...]
>>
>> You can't. The forum is backed by a newsgroup, just post the full corrected version :)
>>
>> -Steve
>
> Thank you :)
>
> Here is th corrected version :
>
> Hi,
>
>   I have a struct with some methods int it, let's say
>
> ```
> struct Example{
>    int a(){
>    	  return someValue;
>    }
>
>    float b(){
> 	  return someOtherValue;
>    }
>
>    string stringValue(){
>       return c;
>    }
> }
>
> Is there any way to have a asTuple method in this struct that would returns something like :
>
> Tuple!(int, "a", float, "b", string, "c")
>
> and that will contain the values of the methods of the struct ?
>
> Thanks.

in the declaration set the return type to 'auto'.
Use 'tuple' instead of 'Tuple'.

June 19, 2015
On Friday, 19 June 2015 at 13:40:01 UTC, Baz wrote:
> On Friday, 19 June 2015 at 13:27:15 UTC, Quentin Ladeveze wrote:
>> On Friday, 19 June 2015 at 13:26:03 UTC, Steven Schveighoffer wrote:
>>> [...]
>>
>> Thank you :)
>>
>> Here is th corrected version :
>>
>> Hi,
>>
>>   I have a struct with some methods int it, let's say
>>
>> ```
>> struct Example{
>>    int a(){
>>    	  return someValue;
>>    }
>>
>>    float b(){
>> 	  return someOtherValue;
>>    }
>>
>>    string stringValue(){
>>       return c;
>>    }
>> }
>>
>> Is there any way to have a asTuple method in this struct that would returns something like :
>>
>> Tuple!(int, "a", float, "b", string, "c")
>>
>> and that will contain the values of the methods of the struct ?
>>
>> Thanks.
>
> in the declaration set the return type to 'auto'.
> Use 'tuple' instead of 'Tuple'.

Ah, damn, haven't see Steven Schveighoffer answer while i was writing. cross post. same thing.
June 19, 2015
On Friday, 19 June 2015 at 13:38:45 UTC, Steven Schveighoffer wrote:
>
> Does this work for you, or is there a further expectation?
>
> auto asTuple() { return Tuple!(int, "a", ...)(a, b, stringValue);}
>
> -Steve

In fact, I was trying to use traits to create the tuple automatically and being able to add or remove methods to the struct without breaking the asTuple method.
I used allMembers for the name of the methods, but I didn't found anything for their return types or their values.

Thank you.
June 19, 2015
On Friday, 19 June 2015 at 13:52:54 UTC, Quentin Ladeveze wrote:
> On Friday, 19 June 2015 at 13:38:45 UTC, Steven Schveighoffer wrote:
>>
>> Does this work for you, or is there a further expectation?
>>
>> auto asTuple() { return Tuple!(int, "a", ...)(a, b, stringValue);}
>>
>> -Steve
>
> In fact, I was trying to use traits to create the tuple automatically and being able to add or remove methods to the struct without breaking the asTuple method.
> I used allMembers for the name of the methods, but I didn't found anything for their return types or their values.
>
> Thank you.

when the return type is defined inside the function it's called a 'Voldemort type',
see http://www.drdobbs.com/cpp/voldemort-types-in-d/232901591?pgno=2
June 19, 2015
On Fri, 19 Jun 2015 13:52:52 +0000
Quentin Ladeveze via Digitalmars-d-learn
<digitalmars-d-learn@puremagic.com> wrote:

> On Friday, 19 June 2015 at 13:38:45 UTC, Steven Schveighoffer wrote:
> >
> > Does this work for you, or is there a further expectation?
> >
> > auto asTuple() { return Tuple!(int, "a", ...)(a, b, stringValue);}
> >
> > -Steve
> 
> In fact, I was trying to use traits to create the tuple
> automatically and being able to add or remove methods to the
> struct without breaking the asTuple method.
> I used allMembers for the name of the methods, but I didn't found
> anything for their return types or their values.
> 
> Thank you.
http://dlang.org/phobos/std_traits.html#ReturnType http://dlang.org/phobos/std_traits.html#ParameterTypeTuple
« First   ‹ Prev
1 2