opEquals nothrow
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 20 08:32:37 PDT 2017
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
More information about the Digitalmars-d-learn
mailing list