I currently have a situation where I want to have a function that
accepts a parameter optionally.
I thought maybe Nullable!int might work:
void foo(Nullable!int) {}
void main()
{
foo(1); // error
int x;
foo(x); // error
}
Apparently, I have to manually wrap an int to get it to pass.
On 2018-04-01 17:54, Steven Schveighoffer wrote:
I currently have a situation where I want to have a function that
accepts a parameter optionally.
I thought maybe Nullable!int might work:
void foo(Nullable!int) {}
void main()
{
foo(1); // error
int x;
foo(x); // error
}
Apparentl
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
wrote:
void main()
{
foo(1); // error
int x;
foo(x); // error
}
For the first line, I had the same problem a while ago...
https://issues.dlang.org/show_bug.cgi?id=15792
On Sunday, April 01, 2018 11:54:16 Steven Schveighoffer via Digitalmars-d-
learn wrote:
> I currently have a situation where I want to have a function that
> accepts a parameter optionally.
>
> I thought maybe Nullable!int might work:
>
> void foo(Nullable!int) {}
>
> void main()
> {
> foo(1);
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
wrote:
I currently have a situation where I want to have a function
that accepts a parameter optionally.
I would simply use a pointer for this. Fighting D grammar seems
too much of a hassle for such simple task.
On Sunday, April 01, 2018 22:06:57 Boris-Barboris via Digitalmars-d-learn
wrote:
> On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
>
> wrote:
> > I currently have a situation where I want to have a function
> > that accepts a parameter optionally.
>
> I would simply use a pointer for
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
wrote:
I currently have a situation where I want to have a function
that accepts a parameter optionally.
I thought maybe Nullable!int might work:
void foo(Nullable!int) {}
void main()
{
foo(1); // error
int x;
foo(x); // e
On Sunday, 1 April 2018 at 22:25:45 UTC, Jonathan M Davis wrote:
How would a pointer help? Instead of doing
foo(nullable(42))
he'd have to do
foo(new int(42))
which is just one character shorter and ends up allocating on
the heap, unlike with Nullable.
- Jonathan M Davis
foo(&x);
On Sunday, April 01, 2018 22:37:17 Boris-Barboris via Digitalmars-d-learn
wrote:
> On Sunday, 1 April 2018 at 22:25:45 UTC, Jonathan M Davis wrote:
> > How would a pointer help? Instead of doing
> >
> > foo(nullable(42))
> >
> > he'd have to do
> >
> > foo(new int(42))
> >
> > which is just one ch
On Sunday, April 01, 2018 22:34:16 Seb via Digitalmars-d-learn wrote:
> On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
>
> wrote:
> > I currently have a situation where I want to have a function
> > that accepts a parameter optionally.
> >
> > I thought maybe Nullable!int might work:
On Sunday, 1 April 2018 at 22:44:45 UTC, Jonathan M Davis wrote:
Which doesn't work in @safe code and doesn't work when you have
an rvalue as you would when passing 42. Ultimately, using
pointers ultimately either requires explicitly allocating stuff
on the heap to be able to pass rvalues, or i
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
wrote:
I currently have a situation where I want to have a function
that accepts a parameter optionally.
why not simply use function overloading?
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
wrote:
I currently have a situation where I want to have a function
that accepts a parameter optionally.
I thought maybe Nullable!int might work:
void foo(Nullable!int) {}
void main()
{
foo(1); // error
int x;
foo(x); // e
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
wrote:
I currently have a situation where I want to have a function
that accepts a parameter optionally.
I thought maybe Nullable!int might work:
void foo(Nullable!int) {}
void main()
{
foo(1); // error
int x;
foo(x); // e
On Monday, 2 April 2018 at 09:31:35 UTC, Timoses wrote:
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
wrote:
I currently have a situation where I want to have a function
that accepts a parameter optionally.
I thought maybe Nullable!int might work:
void foo(Nullable!int) {}
vo
On 4/1/18 12:00 PM, Jacob Carlborg wrote:
Yeah, D doesn't allow user defined implicit conversions, which I think
is required for this. I would make function overloading even more
complex than it is today.
Although it would be really handy for cases like this.
Not necessarily implicit con
On 4/2/18 5:31 AM, Timoses wrote:
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer wrote:
I currently have a situation where I want to have a function that
accepts a parameter optionally.
I thought maybe Nullable!int might work:
void foo(Nullable!int) {}
void main()
{
foo(1);
On 4/1/18 6:01 PM, Jonathan M Davis wrote:
On Sunday, April 01, 2018 11:54:16 Steven Schveighoffer via Digitalmars-d-
learn wrote:
I currently have a situation where I want to have a function that
accepts a parameter optionally.
I thought maybe Nullable!int might work:
void foo(Nullable!int) {
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
wrote:
I currently have a situation where I want to have a function
that accepts a parameter optionally.
This is what function overloading and/or default values are for,
right?
On Wednesday, 4 April 2018 at 08:08:40 UTC, Dejan Lekic wrote:
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
wrote:
I currently have a situation where I want to have a function
that accepts a parameter optionally.
This is what function overloading and/or default values are
for
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
wrote:
But I'd rather avoid such things if possible. Is there a way
around this? Seems rather limiting that I can do:
Is this what you're looking for?
void foo(Nullable!int x = Nullable!int.init)
{ if (!x.isNull) x.get.writeln;
On 4/4/18 8:59 AM, Dukc wrote:
Is this what you're looking for?
See my original post:
I know I can do things like this:
void foo(int x) { return foo(nullable(x)); }
-Steve
On Wednesday, 4 April 2018 at 15:44:34 UTC, Steven Schveighoffer
wrote:
See my original post:
I know I can do things like this:
void foo(int x) { return foo(nullable(x)); }
-Steve
Oops, I read only the body of that function and thought it's a
main function constructiong nullable when call
is it possible to create a delegate that takes an optional number
of parameters and/or return type?
T delegate(S...)(S) special_delegate;
I guess this is impossible?
On Sunday, 2 April 2017 at 19:24:14 UTC, Inquie wrote:
is it possible to create a delegate that takes an optional
number of parameters and/or return type?
T delegate(S...)(S) special_delegate;
I guess this is impossible?
alias Dg(Return, Params...) = Return delegate(Params);
Dg!(int,float,
On Sunday, 2 April 2017 at 20:02:56 UTC, Basile B. wrote:
On Sunday, 2 April 2017 at 19:24:14 UTC, Inquie wrote:
is it possible to create a delegate that takes an optional
number of parameters and/or return type?
T delegate(S...)(S) special_delegate;
I guess this is impossible?
alias Dg(Ret
On Sunday, 2 April 2017 at 20:48:09 UTC, Inquie wrote:
On Sunday, 2 April 2017 at 20:02:56 UTC, Basile B. wrote:
On Sunday, 2 April 2017 at 19:24:14 UTC, Inquie wrote:
is it possible to create a delegate that takes an optional
number of parameters and/or return type?
T delegate(S...)(S) speci
On Sunday, 2 April 2017 at 21:47:55 UTC, Basile B. wrote:
On Sunday, 2 April 2017 at 20:48:09 UTC, Inquie wrote:
On Sunday, 2 April 2017 at 20:02:56 UTC, Basile B. wrote:
On Sunday, 2 April 2017 at 19:24:14 UTC, Inquie wrote:
is it possible to create a delegate that takes an optional
number of
On 04/02/2017 03:24 PM, Inquie wrote:
>> Show a usage, someone certainly propose a pattern that does the job.
>
> int delegate() f;
> void delegate(int) f;
That won't work because both of those are variables and variables don't
have overloading.
> These are effectively overload methods, but m
On Monday, 3 April 2017 at 03:08:22 UTC, Ali Çehreli wrote:
On 04/02/2017 03:24 PM, Inquie wrote:
>> Show a usage, someone certainly propose a pattern that does
the job.
>
> int delegate() f;
> void delegate(int) f;
That won't work because both of those are variables and
variables don't have o
On Monday, 3 April 2017 at 05:00:15 UTC, Inquie wrote:
Yes, but they are really not any different. They only look
different. A field can be a function just like a method because
they look exactly the same except on is in a vtable and the
other is in the fields memory. But both point functions.
31 matches
Mail list logo