Skip to content

Conversation

@T-640
Copy link

@T-640 T-640 commented Oct 18, 2023

Greetings!

Due to Windows having "min" and "max" defined as macros a compile error occurs whenever Windows.h and svector.h headers are included together on that system.

It results in the following error:

...svector.h:137: error: C2589: '(': illegal token on right side of '::'

Here is the code to demonstrate the issue:

#include <Windows.h> // <-- The culprit right here!
#include <iostream>
#include "svector.h"

int main (int, char *[])
{
    ankerl::svector <int, 10> vector {1, 2, 3, 4, 5};
    for (int i : vector)
        std::cout << i << std::endl;
    return 0;
}

The changes proposed simpy add parentheses around statements with std::min and std::max. It appears to be the easiest and least intrusive solution, no need to do things like messing with NOMINMAX macro, for instance.

Further reading:

https://stackoverflow.com/questions/1394132/macro-and-member-function-conflict
https://learn.microsoft.com/en-us/windows/win32/multimedia/min
https://learn.microsoft.com/en-us/windows/win32/multimedia/max

Fixes clash with Windows "min" and "max" macros
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant