Topic: deleted functions
Author: snk_kid <korcanh@googlemail.com>
Date: Sun, 13 Jun 2010 15:51:12 CST Raw View
I was just looking at the current working draft, I can see a
definition of what can be a "defaulted function" like "only special
member functions" but in the section of deleted functions I see no
such definition/restrictions. Does this mean we can write (template)
free-functions which can be "deleted" too? if not it seems like an
unnecessary & inconsistent restriction because it forces programmers
to use SFINAE tricks (enable_if) to emulate that behavior for
(template) free-functions and use language feature (= delete) for
member functions.
If we can't have deleted functions for free-functions I think this
should be clearly defined in the ISO spec just like it is for
"defaulted" functions.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: =3D?ISO-8859-1?Q?Daniel_Kr=3DFCgler?=3D <daniel.kruegler@googlemail.c=.om>
Date: Mon, 14 Jun 2010 14:39:36 CST Raw View
On 13 Jun., 23:51, snk_kid <korc...@googlemail.com> wrote:
> I was just looking at the current working draft, I can see a
> definition of what can be a "defaulted function" like "only special
> member functions" but in the section of deleted functions I see no
> such definition/restrictions. Does this mean we can write (template)
> free-functions which can be "deleted" too?
There is basically no restrictions on deleted functions. Among
these restrictions is that you cannot define main as a deleted
function and that you cannot override a non-deleted function by a
deleted function or override a deleted function by a non-deleted
function.
HTH & Greetings from Bremen,
Daniel Kr=FCgler
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Francis Glassborow <francis.glassborow@btinternet.com>
Date: Mon, 14 Jun 2010 15:23:01 CST Raw View
snk_kid wrote:
> I was just looking at the current working draft, I can see a
> definition of what can be a "defaulted function" like "only special
> member functions" but in the section of deleted functions I see no
> such definition/restrictions. Does this mean we can write (template)
> free-functions which can be "deleted" too? if not it seems like an
> unnecessary & inconsistent restriction because it forces programmers
> to use SFINAE tricks (enable_if) to emulate that behavior for
> (template) free-functions and use language feature (= delete) for
> member functions.
>
> If we can't have deleted functions for free-functions I think this
> should be clearly defined in the ISO spec just like it is for
> "defaulted" functions.
>
But your premise is false. Any function may be declared as deleted and that
is a powerful tool for controlling unwanted conversions.
Quick example:
int foo(int);
int foo(long) = delete;
Now this call becomes a diagnosable error:
foo(0L);
I.e. overload resolution is done first then if it resolves to a deleted
function a diagnostic will result.
At least that was the state of play when I last looked.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: CornedBee <wasti.redl@gmx.net>
Date: Mon, 14 Jun 2010 15:23:36 CST Raw View
On Jun 13, 11:51 pm, snk_kid <korc...@googlemail.com> wrote:
> I was just looking at the current working draft, I can see a
> definition of what can be a "defaulted function" like "only special
> member functions" but in the section of deleted functions I see no
> such definition/restrictions. Does this mean we can write (template)
> free-functions which can be "deleted" too? if not it seems like an
> unnecessary & inconsistent restriction because it forces programmers
> to use SFINAE tricks (enable_if) to emulate that behavior for
> (template) free-functions and use language feature (= delete) for
> member functions.
Any function whatsoever can be defined as deleted. There are no
restrictions. The restrictions on defaulted functions are necessary
because the compiler has to know how to generate defaulted functions,
and it can't except in very special circumstances. There is no reason
to put such restrictions on deleted functions, and no reason to deduce
from the existence of such restrictions on defaulted functions that
their absence in the case of deleted functions is an oversight.
Sebastian
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: snk_kid <korcanh@googlemail.com>
Date: Mon, 14 Jun 2010 18:48:32 CST Raw View
I think you need to re-read what I wrote, I know that, I was asking if
you could have deleted free-functions, I was already assuming you can
because the current draft spec says no such restrictions but I wanted
to get clarification. Anyway I got the answer I was looking for so
thanks to the rest.
On 14 June, 22:23, Francis Glassborow
<francis.glassbo...@btinternet.com> wrote:
> snk_kid wrote:
> > I was just looking at the current working draft, I can see a
> > definition of what can be a "defaulted function" like "only special
> > member functions" but in the section of deleted functions I see no
> > such definition/restrictions. Does this mean we can write (template)
> > free-functions which can be "deleted" too? if not it seems like an
> > unnecessary & inconsistent restriction because it forces programmers
> > to use SFINAE tricks (enable_if) to emulate that behavior for
> > (template) free-functions and use language feature (= delete) for
> > member functions.
>
> > If we can't have deleted functions for free-functions I think this
> > should be clearly defined in the ISO spec just like it is for
> > "defaulted" functions.
>
> But your premise is false. Any function may be declared as deleted and
that
> is a powerful tool for controlling unwanted conversions.
>
> Quick example:
>
> int foo(int);
> int foo(long) = delete;
>
> Now this call becomes a diagnosable error:
>
> foo(0L);
>
> I.e. overload resolution is done first then if it resolves to a deleted
> function a diagnostic will result.
>
> At least that was the state of play when I last looked.
>
> --
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use
> mailto:std-...@netlab.cs.rpi.edu<std-c%2B...@netlab.cs.rpi.edu<std-c%252B...@netlab.cs.rpi.edu>
>
> ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html ]
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]