Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
July 20, 2017 opEquals nothrow | ||||
---|---|---|---|---|
| ||||
Hello, im tring to add nothrow keyword in my code, but compilation fails : function 'object.opEquals' is not nothrow its a simple comparison between 2 objects. How to make opEquals nothrow ? thanks |
July 20, 2017 Re: opEquals nothrow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Aldo | On Thursday, 20 July 2017 at 14:38:03 UTC, Aldo wrote:
> Hello,
>
> im tring to add nothrow keyword in my code, but compilation fails :
>
> function 'object.opEquals' is not nothrow
>
>
> its a simple comparison between 2 objects. How to make opEquals nothrow ?
>
> thanks
Could you show some code.
|
July 20, 2017 Re: opEquals nothrow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Aldo | On 7/20/17 10:38 AM, Aldo wrote:
> Hello,
>
> im tring to add nothrow keyword in my code, but compilation fails :
>
> function 'object.opEquals' is not nothrow
>
>
> its a simple comparison between 2 objects. How to make opEquals nothrow ?
You can't. Object.opEquals is not nothrow, so object.opEquals is not nothrow (note the former is the virtual member function, the latter is a global function which is what the compiler actually calls).
It is a legacy limitation. Until we get rid of all the Object base methods for things like opEquals and toHash, we will not be able to fix this.
-Steve
|
July 20, 2017 Re: opEquals nothrow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Thursday, 20 July 2017 at 14:59:50 UTC, Steven Schveighoffer wrote: > On 7/20/17 10:38 AM, Aldo wrote: >> Hello, >> >> im tring to add nothrow keyword in my code, but compilation fails : >> >> function 'object.opEquals' is not nothrow >> >> >> its a simple comparison between 2 objects. How to make opEquals nothrow ? > > You can't. Object.opEquals is not nothrow, so object.opEquals is not nothrow (note the former is the virtual member function, the latter is a global function which is what the compiler actually calls). > > It is a legacy limitation. Until we get rid of all the Object base methods for things like opEquals and toHash, we will not be able to fix this. > > -Steve Im using DerelictGLFW3, to process events im doing this : glfwSetMouseButtonCallback(window, &onMouseClick); onMouseClick function must be nothrow. But now I can't do anything in this function because I can't convert my code to nothrow. Can I put a try catch in the body ? extern(C) nothrow { void onMouseClick(GLFWwindow* window, int button, int action, int d) { try { // my code } catch { } } } it seems its working but what about performances ? thanks |
July 20, 2017 Re: opEquals nothrow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Aldo | On 7/20/17 11:10 AM, Aldo wrote: > On Thursday, 20 July 2017 at 14:59:50 UTC, Steven Schveighoffer wrote: >> On 7/20/17 10:38 AM, Aldo wrote: >>> Hello, >>> >>> im tring to add nothrow keyword in my code, but compilation fails : >>> >>> function 'object.opEquals' is not nothrow >>> >>> >>> its a simple comparison between 2 objects. How to make opEquals nothrow ? >> >> You can't. Object.opEquals is not nothrow, so object.opEquals is not nothrow (note the former is the virtual member function, the latter is a global function which is what the compiler actually calls). >> >> It is a legacy limitation. Until we get rid of all the Object base methods for things like opEquals and toHash, we will not be able to fix this. >> > > Im using DerelictGLFW3, to process events im doing this : > > glfwSetMouseButtonCallback(window, &onMouseClick); > > onMouseClick function must be nothrow. > > But now I can't do anything in this function because I can't convert my code to nothrow. > > Can I put a try catch in the body ? Yes. > > extern(C) nothrow > { > void onMouseClick(GLFWwindow* window, int button, int action, int d) > { > try > { > // my code > } > catch > { > > } > } > } > > it seems its working but what about performances ? As long as you don't have any code that throws, it should be pretty close to optimal. -Steve |
July 20, 2017 Re: opEquals nothrow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Aldo | On Thursday, 20 July 2017 at 15:10:24 UTC, Aldo wrote:
> extern(C) nothrow
> {
> void onMouseClick(GLFWwindow* window, int button, int action, int d)
> {
> try
> {
> // my code
> }
> catch
> {
>
> }
> }
> }
Tangent but an easy way of nothrowing:
extern(C) nothrow
{
void onMouseClick(GLFWwindow* window, int button, int action, int d)
{
scope(failure) return;
// my throwing code
}
}
or scope(failure) return -1; if working with error codes.
|
July 20, 2017 Re: opEquals nothrow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Aldo | On Thursday, 20 July 2017 at 15:10:24 UTC, Aldo wrote: > On Thursday, 20 July 2017 at 14:59:50 UTC, Steven Schveighoffer wrote: >> On 7/20/17 10:38 AM, Aldo wrote: >>> Hello, >>> >>> im tring to add nothrow keyword in my code, but compilation fails : >>> >>> function 'object.opEquals' is not nothrow >>> >>> >>> its a simple comparison between 2 objects. How to make opEquals nothrow ? >> >> You can't. Object.opEquals is not nothrow, so object.opEquals is not nothrow (note the former is the virtual member function, the latter is a global function which is what the compiler actually calls). >> >> It is a legacy limitation. Until we get rid of all the Object base methods for things like opEquals and toHash, we will not be able to fix this. >> >> -Steve > > Im using DerelictGLFW3, to process events im doing this : > > glfwSetMouseButtonCallback(window, &onMouseClick); > > onMouseClick function must be nothrow. > > But now I can't do anything in this function because I can't convert my code to nothrow. > > Can I put a try catch in the body ? > > extern(C) nothrow > { > void onMouseClick(GLFWwindow* window, int button, int action, int d) > { > try > { > // my code > } > catch > { > > } > } > } > > it seems its working but what about performances ? > > thanks You could also try assumeWontThrow. https://dlang.org/library/std/exception/assume_wont_throw.html |
Copyright © 1999-2021 by the D Language Foundation