-
Notifications
You must be signed in to change notification settings - Fork 592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for span<T> as a sequence view-type #1969
Changes from all commits
ac11461
421b456
2a4f5e6
c8b3933
35bb0fb
7abcfec
3ae848b
de35dbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
#include "CommunicatorF.h" | ||
#include "InstanceF.h" | ||
#include "Object.h" | ||
#include "ValueF.h" | ||
#include "ProxyF.h" | ||
#include "LoggerF.h" | ||
|
@@ -22,6 +21,7 @@ | |
|
||
#include <cassert> | ||
#include <cstdint> | ||
#include <map> | ||
#include <string> | ||
#include <string_view> | ||
|
||
|
@@ -81,7 +81,7 @@ namespace Ice | |
* You can supply a communicator later by calling initialize(). | ||
* @param bytes The encoded data. | ||
*/ | ||
InputStream(const std::pair<const std::byte*, const std::byte*>& bytes); | ||
InputStream(std::pair<const std::byte*, const std::byte*> bytes); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now pass pairs of pointers by value instead of const&, just like other "view types". |
||
|
||
/// \cond INTERNAL | ||
InputStream(IceInternal::Buffer&, bool = false); | ||
|
@@ -105,7 +105,7 @@ namespace Ice | |
* @param communicator The communicator to use for unmarshaling tasks. | ||
* @param bytes The encoded data. | ||
*/ | ||
InputStream(const CommunicatorPtr& communicator, const std::pair<const std::byte*, const std::byte*>& bytes); | ||
InputStream(const CommunicatorPtr& communicator, std::pair<const std::byte*, const std::byte*> bytes); | ||
|
||
/// \cond INTERNAL | ||
InputStream(const CommunicatorPtr& communicator, IceInternal::Buffer&, bool = false); | ||
|
@@ -138,7 +138,7 @@ namespace Ice | |
* @param version The encoding version used to encode the data to be unmarshaled. | ||
* @param bytes The encoded data. | ||
*/ | ||
InputStream(const EncodingVersion& version, const std::pair<const std::byte*, const std::byte*>& bytes); | ||
InputStream(const EncodingVersion& version, std::pair<const std::byte*, const std::byte*> bytes); | ||
|
||
/// \cond INTERNAL | ||
InputStream(const EncodingVersion&, IceInternal::Buffer&, bool = false); | ||
|
@@ -171,7 +171,7 @@ namespace Ice | |
InputStream( | ||
const CommunicatorPtr& communicator, | ||
const EncodingVersion& version, | ||
const std::pair<const std::byte*, const std::byte*>& bytes); | ||
std::pair<const std::byte*, const std::byte*> bytes); | ||
|
||
/// \cond INTERNAL | ||
InputStream(const CommunicatorPtr&, const EncodingVersion&, IceInternal::Buffer&, bool = false); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,10 @@ | |
#include <optional> | ||
#include <string_view> | ||
|
||
#if __has_include(<span>) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the preferred and portable way to conditionally include span. Span is a c++20 and up feature. |
||
# include <span> | ||
#endif | ||
|
||
namespace Ice | ||
{ | ||
/// \cond STREAM | ||
|
@@ -491,14 +495,30 @@ namespace Ice | |
*/ | ||
template<typename T> struct StreamHelper<std::pair<const T*, const T*>, StreamHelperCategorySequence> | ||
{ | ||
template<class S> static inline void write(S* stream, const std::pair<const T*, const T*>& v) | ||
template<class S> static inline void write(S* stream, std::pair<const T*, const T*> v) | ||
{ | ||
stream->write(v.first, v.second); | ||
} | ||
|
||
template<class S> static inline void read(S* stream, std::pair<const T*, const T*>& v) { stream->read(v); } | ||
}; | ||
|
||
#ifdef __cpp_lib_span | ||
/** | ||
* Helper for span (C++20 or later). | ||
* \headerfile Ice/Ice.h | ||
*/ | ||
template<typename T> struct StreamHelper<std::span<T>, StreamHelperCategorySequence> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the actual core for this PR - not much. The bulk of the additional code is the new span test. |
||
{ | ||
template<class S> inline static void write(S* stream, const std::span<T>& v) | ||
{ | ||
stream->write(v.data(), v.data() + v.size()); | ||
} | ||
|
||
// No read. span are only for view types. | ||
}; | ||
#endif | ||
|
||
/** | ||
* Helper for dictionaries. | ||
* \headerfile Ice/Ice.h | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated cleanup - should have been included in a separate PR.