-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[C++] const qualifier on mutable_span_as prevents call to mutable_data_as without const qualifier #40366
Copy link
Copy link
Closed
Description
Describe the bug, including details regarding any error messages, version, and platform.
#38027 added Buffer::span_as and Buffer::mutable_span_as
mutable_span_as has a const qualifier,
Lines 265 to 274 in 53e0c74
| template <typename T> | |
| T* mutable_data_as() { | |
| return reinterpret_cast<T*>(mutable_data()); | |
| } | |
| /// \brief Return the buffer's mutable data as a span | |
| template <typename T> | |
| util::span<T> mutable_span_as() const { | |
| return util::span(mutable_data_as<T>(), static_cast<size_t>(size() / sizeof(T))); | |
| } |
but this prevents the call to mutable_data_as during compile:
...include/arrow/buffer.h:273:41: error: passing ‘const arrow::Buffer’ as ‘this’ argument discards qualifiers [-fpermissive]
273 | return util::span(mutable_data_as<T>(), static_cast<size_t>(size() / sizeof(T)));By contrast, both span_as and data_as have const qualifiers.
Lines 228 to 241 in 53e0c74
| /// \brief Return a pointer to the buffer's data cast to a specific type | |
| /// | |
| /// The buffer has to be a CPU buffer (`is_cpu()` is true). | |
| /// Otherwise, an assertion may be thrown or a null pointer may be returned. | |
| template <typename T> | |
| const T* data_as() const { | |
| return reinterpret_cast<const T*>(data()); | |
| } | |
| /// \brief Return the buffer's data as a span | |
| template <typename T> | |
| util::span<const T> span_as() const { | |
| return util::span(data_as<T>(), static_cast<size_t>(size() / sizeof(T))); | |
| } |
Also, mutable_span_as should not have a const qualifier as it implies modification of arrow::Buffer.
Component(s)
C++
Reactions are currently unavailable