Skip to content

Commit 452f736

Browse files
authored
Merge pull request #416 from gummif/gfa/macro-doc
Problem: Feature checking inconsistencies
2 parents c4d4cf7 + 1fc3a9a commit 452f736

File tree

5 files changed

+35
-15
lines changed

5 files changed

+35
-15
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ int main()
8484
}
8585
```
8686

87+
Compatibility Guidelines
88+
========================
89+
90+
The users of cppzmq are expected to follow the guidelines below to ensure not to break when upgrading cppzmq to newer versions (non-exhaustive list):
91+
92+
* Do not depend on any macros defined in cppzmq unless explicitly declared public here.
93+
94+
The following macros may be used by consumers of cppzmq: `CPPZMQ_VERSION`, `CPPZMQ_VERSION_MAJOR`, `CPPZMQ_VERSION_MINOR`, `CPPZMQ_VERSION_PATCH`.
95+
8796
Contribution policy
8897
===================
8998

tests/buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ TEST_CASE("mutable_buffer creation string", "[buffer]")
222222
CHECK(b2.data() == d.data());
223223
}
224224

225-
#ifdef ZMQ_CPP17
225+
#if CPPZMQ_HAS_STRING_VIEW
226226
TEST_CASE("const_buffer creation string_view", "[buffer]")
227227
{
228228
std::wstring dstr(10, L'a');

tests/message.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ TEST_CASE("message to string", "[message]")
158158
const zmq::message_t b("Foo", 3);
159159
CHECK(a.to_string() == "");
160160
CHECK(b.to_string() == "Foo");
161-
#ifdef ZMQ_CPP17
161+
#if CPPZMQ_HAS_STRING_VIEW
162162
CHECK(a.to_string_view() == "");
163163
CHECK(b.to_string_view() == "Foo");
164164
#endif

tests/socket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ TEST_CASE("socket options", "[socket]")
6969
socket.set(zmq::sockopt::routing_id, "foobar");
7070
socket.set(zmq::sockopt::routing_id, zmq::buffer(id));
7171
socket.set(zmq::sockopt::routing_id, id);
72-
#ifdef ZMQ_CPP17
72+
#if CPPZMQ_HAS_STRING_VIEW
7373
socket.set(zmq::sockopt::routing_id, std::string_view{id});
7474
#endif
7575

zmq.hpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,29 @@
103103
#include <tuple>
104104
#include <memory>
105105
#endif
106-
#ifdef ZMQ_CPP17
107-
#ifdef __has_include
108-
#if __has_include(<optional>)
109-
#include <optional>
110-
#define ZMQ_HAS_OPTIONAL 1
106+
107+
#if defined(__has_include) && defined(ZMQ_CPP17)
108+
#define CPPZMQ_HAS_INCLUDE_CPP17(X) __has_include(X)
109+
#else
110+
#define CPPZMQ_HAS_INCLUDE_CPP17(X) 0
111111
#endif
112-
#if __has_include(<string_view>)
113-
#include <string_view>
114-
#define ZMQ_HAS_STRING_VIEW 1
112+
113+
#if CPPZMQ_HAS_INCLUDE_CPP17(<optional>) && !defined(CPPZMQ_HAS_OPTIONAL)
114+
#define CPPZMQ_HAS_OPTIONAL 1
115115
#endif
116+
#ifndef CPPZMQ_HAS_OPTIONAL
117+
#define CPPZMQ_HAS_OPTIONAL 0
118+
#elif CPPZMQ_HAS_OPTIONAL
119+
#include <optional>
116120
#endif
117121

122+
#if CPPZMQ_HAS_INCLUDE_CPP17(<string_view>) && !defined(CPPZMQ_HAS_STRING_VIEW)
123+
#define CPPZMQ_HAS_STRING_VIEW 1
124+
#endif
125+
#ifndef CPPZMQ_HAS_STRING_VIEW
126+
#define CPPZMQ_HAS_STRING_VIEW 0
127+
#elif CPPZMQ_HAS_STRING_VIEW
128+
#include <string_view>
118129
#endif
119130

120131
/* Version macros for compile-time API version detection */
@@ -582,7 +593,7 @@ class message_t
582593
{
583594
return std::string(static_cast<const char *>(data()), size());
584595
}
585-
#ifdef ZMQ_CPP17
596+
#if CPPZMQ_HAS_STRING_VIEW
586597
// interpret message content as a string
587598
std::string_view to_string_view() const noexcept
588599
{
@@ -830,7 +841,7 @@ struct recv_buffer_size
830841
}
831842
};
832843

833-
#if defined(ZMQ_HAS_OPTIONAL) && (ZMQ_HAS_OPTIONAL > 0)
844+
#if CPPZMQ_HAS_OPTIONAL
834845

835846
using send_result_t = std::optional<size_t>;
836847
using recv_result_t = std::optional<size_t>;
@@ -1237,7 +1248,7 @@ const_buffer buffer(const std::basic_string<T, Traits, Allocator> &data,
12371248
return detail::buffer_contiguous_sequence(data, n_bytes);
12381249
}
12391250

1240-
#if defined(ZMQ_HAS_STRING_VIEW) && (ZMQ_HAS_STRING_VIEW > 0)
1251+
#if CPPZMQ_HAS_STRING_VIEW
12411252
// std::basic_string_view
12421253
template<class T, class Traits>
12431254
const_buffer buffer(std::basic_string_view<T, Traits> data) noexcept
@@ -1662,7 +1673,7 @@ class socket_base
16621673
set_option(Opt, buf.data(), buf.size());
16631674
}
16641675

1665-
#ifdef ZMQ_CPP17
1676+
#if CPPZMQ_HAS_STRING_VIEW
16661677
// Set array socket option, e.g.
16671678
// `socket.set(zmq::sockopt::routing_id, id_str)`
16681679
template<int Opt, int NullTerm>

0 commit comments

Comments
 (0)