Skip to content

Commit

Permalink
Resolve NOMINMAX issues where possible (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgolov authored Dec 23, 2020
1 parent 2c97611 commit 25a8668
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 6 deletions.
11 changes: 11 additions & 0 deletions api/include/opentelemetry/common/spin_lock_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

#include "opentelemetry/version.h"

#if defined(_MSC_VER)
# ifndef NOMINMAX
# define NOMINMAX
# endif
# include <Windows.h>
#elif defined(__i386__) || defined(__x86_64__)
# if defined(__clang__)
# include <emmintrin.h>
# endif
#endif

OPENTELEMETRY_BEGIN_NAMESPACE
namespace common
{
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/nostd/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class string_view

int compare(string_view v) const noexcept
{
size_type len = std::min(size(), v.size());
size_type len = (std::min)(size(), v.size());
int result = Traits::compare(data(), v.data(), len);
if (result == 0)
result = size() == v.size() ? 0 : (size() < v.size() ? -1 : 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
#include "opentelemetry/plugin/hook.h"
#include "opentelemetry/version.h"

#include <windows.h>
#ifndef NOMINMAX
# define NOMINMAX
#endif
#include <Windows.h>

#include <WinBase.h>
#include <errhandlingapi.h>
#include <winbase.h>

OPENTELEMETRY_BEGIN_NAMESPACE
namespace plugin
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/std/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ OPENTELEMETRY_END_NAMESPACE
OPENTELEMETRY_BEGIN_NAMESPACE
namespace nostd
{
constexpr std::size_t dynamic_extent = std::numeric_limits<std::size_t>::max();
constexpr std::size_t dynamic_extent = (std::numeric_limits<std::size_t>::max());

template <class ElementType, std::size_t Extent = nostd::dynamic_extent>
using span = std::span<ElementType, Extent>;
Expand Down
2 changes: 1 addition & 1 deletion ext/include/opentelemetry/ext/http/server/socket_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ struct SocketAddr
{
inet4.sin_port = htons(atoi(colon + 1));
char buf[16];
memcpy(buf, addr, std::min<ptrdiff_t>(15, colon - addr));
memcpy(buf, addr, (std::min<ptrdiff_t>)(15, colon - addr));
buf[15] = '\0';
::inet_pton(AF_INET, buf, &inet4.sin_addr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class SketchAggregator final : public Aggregator<T>
int idx;
if (val == 0)
{
idx = std::numeric_limits<int>::min();
idx = (std::numeric_limits<int>::min());
}
else
{
Expand Down
11 changes: 11 additions & 0 deletions sdk/src/common/fast_random_number_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ namespace common
* std::mt19937_64; and since we don't care about the other beneficial random
* number properties that std:mt19937_64 provides for this application, it's a
* entirely appropriate replacement.
*
* Note for Windows users - please make sure that NOMINMAX is defined, e.g.
*
* ...
* #define NOMINMAX
* #include <Windows.h>
* ...
*
* See:
* https://stackoverflow.com/questions/13416418/define-nominmax-using-stdmin-max
*
*/
class FastRandomNumberGenerator
{
Expand Down

0 comments on commit 25a8668

Please sign in to comment.