A
aleksandar.ristovski
Hello all,
I have been thinking about a possible extension to C/C++ syntax.
The current syntax allows declaring a function that returns a value:
int foo();
however, if I were to return more than one value, for example three
int-s, I would have to change my "logic" and pass the references to my
return values (i.e. declare them in the argument list) or to declare an
extra-struct representing the return type of three ints (extra work and
extra types). The function would look something like:
int foo(int&,int&);
or
void foo(int &, int&, int&);
or
struct rettype
{
int a, b, c;
};
rettype foo();
Would it not be nice if I could keep the thinking "return values are on
the left-hand side" and do something like this:
----
declaration:
{int, int, int} foo();
----
definition:
{int, int, int} foo()
{
...
return {1, 42, 0};
}
I have been thinking about a possible extension to C/C++ syntax.
The current syntax allows declaring a function that returns a value:
int foo();
however, if I were to return more than one value, for example three
int-s, I would have to change my "logic" and pass the references to my
return values (i.e. declare them in the argument list) or to declare an
extra-struct representing the return type of three ints (extra work and
extra types). The function would look something like:
int foo(int&,int&);
or
void foo(int &, int&, int&);
or
struct rettype
{
int a, b, c;
};
rettype foo();
Would it not be nice if I could keep the thinking "return values are on
the left-hand side" and do something like this:
----
declaration:
{int, int, int} foo();
----
definition:
{int, int, int} foo()
{
...
return {1, 42, 0};
}