digitalmars.D.learn - opEquals nothrow
- Aldo (7/7) Jul 20 2017 Hello,
- bauss (2/9) Jul 20 2017 Could you show some code.
- Steven Schveighoffer (8/16) Jul 20 2017 You can't. Object.opEquals is not nothrow, so object.opEquals is not
- Aldo (24/43) Jul 20 2017 Im using DerelictGLFW3, to process events im doing this :
- Steven Schveighoffer (5/53) Jul 20 2017 As long as you don't have any code that throws, it should be pretty
- Anonymouse (12/26) Jul 20 2017 Tangent but an easy way of nothrowing:
- w0rp (3/49) Jul 20 2017 You could also try assumeWontThrow.
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
Jul 20 2017
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 ? thanksCould you show some code.
Jul 20 2017
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
Jul 20 2017
On Thursday, 20 July 2017 at 14:59:50 UTC, Steven Schveighoffer wrote:On 7/20/17 10:38 AM, Aldo wrote: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 ? thanksHello, 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
Jul 20 2017
On 7/20/17 11:10 AM, Aldo wrote:On Thursday, 20 July 2017 at 14:59:50 UTC, Steven Schveighoffer wrote:Yes.On 7/20/17 10:38 AM, Aldo wrote: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 ?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.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
Jul 20 2017
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.
Jul 20 2017
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:You could also try assumeWontThrow. https://dlang.org/library/std/exception/assume_wont_throw.htmlOn 7/20/17 10:38 AM, Aldo wrote: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 ? thanksHello, 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
Jul 20 2017