Topic: Core Language issue 226 (was: Default argument specified but not used?)
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: 22 Jun 2002 00:35:43 GMT Raw View
In article <3D12D513.B7126439@aixigo.de>, Daniel Frey
<daniel.frey@aixigo.de> writes
>As you can always use overloads instead of default parameters, why do we
>need default parameters anyway? Because it keeps your code clearer and
>easier to maintain.
Not in my opinion. We have such horrors as different default parameters
in different TUs. We also have distorted ordering of parameters to allow
the most likely to be defaulted to be the last one.
Well written overloads do all that default parameters can do and more.
They are just as easy to maintain. (The overloads equivalent to default
parameters should be simple forwarding functions and need no
maintenance, indeed, that allows you to change the default without
recompiling everything)
--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ 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: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Thu, 20 Jun 2002 17:28:16 GMT Raw View
In article <3D0DAA10.F2E3D027@aixigo.de>, Daniel Frey
<daniel.frey@aixigo.de> writes
>But I can live with having to provide 'typename U = Null' additionally
>to 'const U& u = null'. Still C++ proves its complexity once again
>(IMHO). I hope that compilers will at least give a warning about a
>possible ambiguous situation for code like the example I gave as it is
>not obvious why the default is ignored and another function is called
>instead.
As we are considering function templates why not just overload the
template function. This is just one more place where pre-occupation with
default parameters buys nothing.
--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ 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: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Sat, 15 Jun 2002 16:27:27 GMT Raw View
In article <3D0A18F5.2006BA9C@aixigo.de>, Daniel Frey
<daniel.frey@aixigo.de> writes
>Hi,
>
>I recently posted this little code fragment:
>
>> #include <iostream>
>> #include <typeinfo>
>>
>> class Null {} null;
>>
>> template< typename T, typename U >
At this point you make a promise that either the compiler will be able
to deduce the types of T and U or you will provide them explicitly.
>> void f( const T& t, const U& u = null )
At this point the compiler needs a value of null for whatever type U is.
Note that despite your definition above, U might be a type with a null
value provided in its namespace. The compiler cannot, at this stage,
deduce that U must be Null, it must first know what type U represents
and then seek a value 'null' for it.
>> {
>> std::cout << typeid( t ).name() << " - "
>> << typeid( u ).name() << std::endl;
>> }
>>
>> int main()
>> {
>> f( 42, 21 );
>> f( 42 );
If you wrote f<int, Null>(42);
I think all should be fine, but there is no mechanism to deduce that
second type parameter from your provided code.
>> }
--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ 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: Daniel Frey <daniel.frey@aixigo.de>
Date: Sat, 15 Jun 2002 06:19:35 GMT Raw View
Hi,
I recently posted this little code fragment:
> #include <iostream>
> #include <typeinfo>
>=20
> class Null {} null;
>=20
> template< typename T, typename U >
> void f( const T& t, const U& u =3D null )
> {
> std::cout << typeid( t ).name() << " - "
> << typeid( u ).name() << std::endl;
> }
>=20
> int main()
> {
> f( 42, 21 );
> f( 42 );
> }
As I understand,
http://std.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#226 would
suggest to use:
template< typename T, typename U =3D Null >
void f( const T& t, const U& u =3D null ) { ... }
and the code should compile (well, some day in the future...). The text
in the C++ standard core language active issues" focuses on the default
template argument, so at least the will be a partial solution to prevent
helper functions. But the question to me still remains: Why is the
default for the function argument not used? Shouldn't the language
either couple the occurrence of the defaults or shouldn't the existance
of a default function parameter be used to deduce the template argument?
Isn't this a defect in the current standard? Or are there references to
other "issues", "non-issues" or even "resolutions" I overlooked?
Regards, Daniel
--
Daniel Frey
aixigo AG - financial training, research and technology
Schlo=DF-Rahe-Stra=DFe 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey@aixigo.de, web: http://www.aixigo.de
---
[ 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 ]