GithubHelp home page GithubHelp logo

Comments (11)

supercairos avatar supercairos commented on June 9, 2024 1

I usually define NOMINMAX as preprocessor def in VS

from cxxopts.

jarro2783 avatar jarro2783 commented on June 9, 2024

Which version of the compiler? I've had a few other people discuss MSVC and they haven't had issues.

Does it also work if you add an extra set of parentheses around the argument to min and max?

from cxxopts.

amigo421 avatar amigo421 commented on June 9, 2024

extra parentheses doesn't solve the problem,
VC toolchain is version 15, aka VisualStudio 2017

this is a known issue, see here or here

the description in MSDN here

from cxxopts.

jarro2783 avatar jarro2783 commented on June 9, 2024

I'm happy to accept a pull request. I wonder if a better option would be to write (std::max)(x, y) as suggested by the StackOverflow answers, rather than #undef.

from cxxopts.

amigo421 avatar amigo421 commented on June 9, 2024

sure, Ill perform a few tests with both variants and raise a request

from cxxopts.

jarro2783 avatar jarro2783 commented on June 9, 2024

Is this still an issue for you?

from cxxopts.

supercairos avatar supercairos commented on June 9, 2024

from cxxopts.

Robmaister avatar Robmaister commented on June 9, 2024

I just picked this up for a project on Windows. Definitely use the built-in NOMINMAX define for Windows.h instead of trying to undef it manually.

If you undef, #include <cxxopts.hpp> would have side-effects for applications assuming that min and max are existing macros in later code, since the preprocessor has no scope.

Proper usage:

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include <Windows.h>

#include <cxxopts.hpp>

An example that would break with #undef:

#include <Windows.h>
#include <cxxopts.hpp>

int main (int argc, char* argv[]) {
    return max(2, 3);
}

from cxxopts.

amigo421 avatar amigo421 commented on June 9, 2024

agreed ,NOMINMAX prefered way and it works fine for me too
request can be closed without modification the library

from cxxopts.

zhongjingjogy avatar zhongjingjogy commented on June 9, 2024

@jarro2783 I am sorry to bother the rest of others about a closed issue. As someone who tries to use cxxopts on windows with MSVC, I found it is very frustrated to deal with MACRO min/max under WINDOWS. I should blame that MSVC introduce such an annoying feature that affects extensively. But I would sugguest that opensource library should provide more friendly solution to third party users. As an example, add parenthesis to anywhere you have min and max as it is suggested by NIRO

(std::numeric_limits<size_type>::max)()
(std::min)
(std::max)

As it is said,

No need for the NOMINMAX macro in this case, plus you won't get compiler warnings

I wrote this in memory of my lost 30 minutes at this time.

from cxxopts.

jarro2783 avatar jarro2783 commented on June 9, 2024

That seems like a reasonable workaround. I'll make the changes at some point soonish.

from cxxopts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.