Git Product home page Git Product logo

Comments (4)

T-Deuty avatar T-Deuty commented on June 7, 2024

This seems to require the NOMINMAX preprocessor definition. I'd suggest adding that with the check for if its already defined before wherever windows.h is included, if in fact it is included.

Perhaps it isn't in the GIL library and its just my large project, but I'm running into issues when I need both this to compile and code using the standard MAX macro.

Edit:
Adding this link to a separate issue where the same problem I'm trying to describe is brought up: boostorg/stacktrace#76

from gil.

mloskot avatar mloskot commented on June 7, 2024

@T-Deuty

This seems to require the NOMINMAX preprocessor definition

Yes, Windows SDK/MSVC, in many, if not most uses of std::numeric_limits<T>::max() will either require to #define NOMINMAX or function-like macro suppression with extra parentheses (std::numeric_limits<T>::max)() or one of several other possible tricks to work around the Windows SDK/MSVC annoyance.

I'd suggest adding that with the check for if its already defined before wherever windows.h is included, if in fact it is included.

AFAICT, nowhere in GIL the windows.h is included. However, to ensure building tests/examples is not prone to this annoyance, we #define NOMINMAX in the build configurations:

<toolset>msvc:<define>NOMINMAX

$<$<CXX_COMPILER_ID:MSVC>:NOMINMAX>

IMO, it is not GIL or Boost or other C++ library duty but a library's user duty to #define NOMINMAX before any Windows header, as suggested by LLVM/clang/libcxx infrastructure:

#ifdef min
#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
#if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("macro min is incompatible with C++.  Try #define NOMINMAX "
                "before any Windows header. #undefing min")
#else
#warning: macro min is incompatible with C++.  #undefing min
#endif
#endif
#undef min
#endif

Alternatively, we may consider adding very similar check and warning somewhere in boost/gil.hpp. What do you think, @stefanseefeld ?

from gil.

T-Deuty avatar T-Deuty commented on June 7, 2024

Thanks for getting back to me so quickly. I agree with your opinion that it is on the library user to handle this, I'll look into defining NOMINMAX for my project. I was doing so until I came across an error where we're using what I think is a standard definition of max, in another library, that won't compile with NOMINMAX defined. So feels like a catch 22 between using GIL and this other library.

We're using Boost-gil 1.70 from Vcpkg by the way. My vote would be for the "function-like macro suppression with extra parenthesis" but in the meantime I'll try to find all the Windows headers and define NOMINMAX before including them.

Thanks,
Tyler

from gil.

mloskot avatar mloskot commented on June 7, 2024

My vote would be for the "function-like macro suppression with extra parenthesis"

I've searched through the code and apparently GIL already uses this technique in numerous places, e.g.

get_color(dst,black_t()) = (std::min)(get_color(dst,cyan_t()),
(std::min)(get_color(dst,magenta_t()),

as well as explicit template parameter to suppress the macro:

std::ptrdiff_t const num = std::min<std::ptrdiff_t>(n, i2.width() - i2.x_pos());

Please, consider contributing a pull request with similar fixes that will help your project.
Since such technique is already in use, I don't see any reason why we shouldn't accept it.

from gil.

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.