svector icon indicating copy to clipboard operation
svector copied to clipboard

Fix for clash with Windows "min" and "max" macros

Open T-640 opened this issue 1 year ago • 0 comments

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

T-640 avatar Oct 18 '23 05:10 T-640