www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - opEquals nothrow

reply Aldo <aldocd4 outlook.com> writes:
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
next sibling parent bauss <jj_1337 live.dk> writes:
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.
Jul 20 2017
prev sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
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
parent reply Aldo <aldocd4 outlook.com> writes:
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
Jul 20 2017
next sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
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
Jul 20 2017
prev sibling next sibling parent Anonymouse <asdf asdf.net> writes:
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
prev sibling parent w0rp <devw0rp gmail.com> writes:
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
Jul 20 2017