Topic: Default arguments


Author: dave@boost-consulting.com (David Abrahams)
Date: Mon, 5 Apr 2004 18:31:38 +0000 (UTC)
Raw View
nospam@nospam.invalid (Squider) writes:

> I don't know whether or not this issue has been discussed here before
> but here goes:
>
> If I have a function
>
>    int f(int a = 0, int b = 1);
>
> and I'd like to call the function with the first argument's default
> value and a custom default argument, I'd have to write something like:
>
>    f(0, 2);
>
> And in some cases, I'd like to omit the second argument:
>
>    f(4);
>
> This makes me repeat the default argument for the function in the code
> that calls the function, hence making me do a bunch of replacements if I
> decide to change the default value. I think it would be better to be
> able to write something like
>
>    f(, 2);
>
> when wanting to omit a specific argument.
>
> What do you think?

I think we need named function parameters.
See http://tinyurl.com/2qtkk ;-)

--
Dave Abrahams
Boost Consulting
www.boost-consulting.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: nospam@nospam.invalid (Squider)
Date: Fri, 2 Apr 2004 19:04:32 +0000 (UTC)
Raw View
I don't know whether or not this issue has been discussed here before
but here goes:

If I have a function

   int f(int a = 0, int b = 1);

and I'd like to call the function with the first argument's default
value and a custom default argument, I'd have to write something like:

   f(0, 2);

And in some cases, I'd like to omit the second argument:

   f(4);

This makes me repeat the default argument for the function in the code
that calls the function, hence making me do a bunch of replacements if I
decide to change the default value. I think it would be better to be
able to write something like

   f(, 2);

when wanting to omit a specific argument.

What do you think?

--
Jukka Helle (Squider) <squidysoft dot squider at dnainternet dot net>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: technews@kangaroologic.com ("Jonathan Turkanis")
Date: Fri, 2 Apr 2004 22:06:39 +0000 (UTC)
Raw View
"Squider" <nospam@nospam.invalid> wrote in message
news:406dabb9$1_2@news.dnainternet.net...
> I don't know whether or not this issue has been discussed here
before
> but here goes:
>
> If I have a function
>
>    int f(int a = 0, int b = 1);
>
> and I'd like to call the function with the first argument's default
> value and a custom default argument, I'd have to write something
like:
>
>    f(0, 2);
>

<snip>

> decide to change the default value. I think it would be better to be
> able to write something like
>
>    f(, 2);
>

This has been proposed, with the syntax:

     f(default, 2);

See http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1466.pdf

In addition, David Abrahams and Daniel Wallin have a library submitted
to Boost which allows the simulation of named function parameters, so
you can invoke functions like this:

       f(name = "foo", value = 3.14f);
       f(value = 3.14f);

See

    http://groups.yahoo.com/group/boost/files/named_params.zip

(You need to join the Boost developers list to access this link.)

Jonathan


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: nospam@nospam.invalid (Squider)
Date: Fri, 2 Apr 2004 23:17:06 +0000 (UTC)
Raw View
Jonathan Turkanis wrote:

> This has been proposed, with the syntax:
>
>      f(default, 2);
>

Oh that is really nice since default already is a keyword.

Thank you very much for the information.

--
Jukka Helle (Squider) <squidysoft dot squider at dnainternet dot net>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]