mirror of
https://github.com/zeromq/cppzmq.git
synced 2025-05-29 07:25:56 +02:00
Explicitly check for optional and string_view in cases where the C++17 language is operational but the standard library in use does not have those headers.
add check for using stdlibc++ with clang or icc to make sure is_trivially_copyable is available.
This commit is contained in:
parent
ca1ca7caae
commit
d5cbaf4682
21
zmq.hpp
21
zmq.hpp
@ -87,7 +87,17 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZMQ_CPP17
|
#ifdef ZMQ_CPP17
|
||||||
|
#ifdef __has_include
|
||||||
|
#if __has_include(<optional>)
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#define ZMQ_HAS_OPTIONAL 1
|
||||||
|
#endif
|
||||||
|
#if __has_include(<string_view>)
|
||||||
|
#include <string_view>
|
||||||
|
#define ZMQ_HAS_STRING_VIEW 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Version macros for compile-time API version detection */
|
/* Version macros for compile-time API version detection */
|
||||||
@ -127,12 +137,17 @@
|
|||||||
#if defined(ZMQ_CPP11) && !defined(__llvm__) && !defined(__INTEL_COMPILER) \
|
#if defined(ZMQ_CPP11) && !defined(__llvm__) && !defined(__INTEL_COMPILER) \
|
||||||
&& defined(__GNUC__) && __GNUC__ < 5
|
&& defined(__GNUC__) && __GNUC__ < 5
|
||||||
#define ZMQ_CPP11_PARTIAL
|
#define ZMQ_CPP11_PARTIAL
|
||||||
|
#elif defined(__GLIBCXX__) && __GLIBCXX__ < 20160805
|
||||||
|
//the date here is the last date of gcc 4.9.4, which
|
||||||
|
// effectively means libstdc++ from gcc 5.5 and higher won't trigger this branch
|
||||||
|
#define ZMQ_CPP11_PARTIAL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ZMQ_CPP11
|
#ifdef ZMQ_CPP11
|
||||||
#ifdef ZMQ_CPP11_PARTIAL
|
#ifdef ZMQ_CPP11_PARTIAL
|
||||||
#define ZMQ_IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
|
#define ZMQ_IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
|
||||||
#else
|
#else
|
||||||
|
#include <type_traits>
|
||||||
#define ZMQ_IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable<T>::value
|
#define ZMQ_IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable<T>::value
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -700,7 +715,7 @@ struct recv_buffer_size
|
|||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef ZMQ_CPP17
|
#if defined(ZMQ_HAS_OPTIONAL) && (ZMQ_HAS_OPTIONAL > 0)
|
||||||
using send_result_t = std::optional<size_t>;
|
using send_result_t = std::optional<size_t>;
|
||||||
using recv_result_t = std::optional<size_t>;
|
using recv_result_t = std::optional<size_t>;
|
||||||
using recv_buffer_result_t = std::optional<recv_buffer_size>;
|
using recv_buffer_result_t = std::optional<recv_buffer_size>;
|
||||||
@ -1097,7 +1112,7 @@ const_buffer buffer(const std::basic_string<T, Traits, Allocator> &data,
|
|||||||
return detail::buffer_contiguous_sequence(data, n_bytes);
|
return detail::buffer_contiguous_sequence(data, n_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ZMQ_CPP17
|
#if defined(ZMQ_HAS_STRING_VIEW) && (ZMQ_HAS_STRING_VIEW > 0)
|
||||||
// std::basic_string_view
|
// std::basic_string_view
|
||||||
template<class T, class Traits>
|
template<class T, class Traits>
|
||||||
const_buffer buffer(std::basic_string_view<T, Traits> data) noexcept
|
const_buffer buffer(std::basic_string_view<T, Traits> data) noexcept
|
||||||
@ -1121,7 +1136,7 @@ constexpr const_buffer str_buffer(const Char (&data)[N]) noexcept
|
|||||||
#ifdef ZMQ_CPP14
|
#ifdef ZMQ_CPP14
|
||||||
assert(data[N - 1] == Char{0});
|
assert(data[N - 1] == Char{0});
|
||||||
#endif
|
#endif
|
||||||
return const_buffer(static_cast<const Char*>(data),
|
return const_buffer(static_cast<const Char*>(data),
|
||||||
(N - 1) * sizeof(Char));
|
(N - 1) * sizeof(Char));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user