Skip to content

Commit 2c9ef46

Browse files
authored
Merge branch 'master' into table-native-type
2 parents 34f48ba + 5ed02dc commit 2c9ef46

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

include/flatbuffers/array.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ class Array {
3939
typedef VectorConstIterator<T, return_type, uoffset_t> const_iterator;
4040
typedef VectorReverseIterator<const_iterator> const_reverse_iterator;
4141

42-
// If T is a LE-scalar or a struct (!scalar_tag::value).
42+
// If T is a non-pointer and a LE-scalar or a struct (!scalar_tag::value).
4343
static FLATBUFFERS_CONSTEXPR bool is_span_observable =
44-
(scalar_tag::value && (FLATBUFFERS_LITTLEENDIAN || sizeof(T) == 1)) ||
45-
!scalar_tag::value;
44+
!std::is_pointer<T>::value &&
45+
((scalar_tag::value && (FLATBUFFERS_LITTLEENDIAN || sizeof(T) == 1)) ||
46+
!scalar_tag::value);
4647

4748
FLATBUFFERS_CONSTEXPR uint16_t size() const { return length; }
4849

include/flatbuffers/vector.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ class Vector {
172172
scalar_tag;
173173

174174
static FLATBUFFERS_CONSTEXPR bool is_span_observable =
175-
scalar_tag::value && (FLATBUFFERS_LITTLEENDIAN || sizeof(T) == 1);
175+
scalar_tag::value && !std::is_pointer<T>::value &&
176+
(FLATBUFFERS_LITTLEENDIAN || sizeof(T) == 1);
176177

177178
SizeT size() const { return EndianScalar(length_); }
178179

@@ -359,6 +360,22 @@ FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span<const uint8_t> make_bytes_span(
359360
return span<const uint8_t>(vec.Data(), vec.size() * sizeof(U));
360361
}
361362

363+
#if FLATBUFFERS_LITTLEENDIAN
364+
365+
template <class U>
366+
FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span<U> make_structs_span(
367+
Vector<const U*>& vec) FLATBUFFERS_NOEXCEPT {
368+
return span<U>(reinterpret_cast<U*>(vec.data()), vec.size());
369+
}
370+
371+
template <class U>
372+
FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span<const U> make_structs_span(
373+
const Vector<const U*>& vec) FLATBUFFERS_NOEXCEPT {
374+
return span<const U>(reinterpret_cast<const U*>(vec.data()), vec.size());
375+
}
376+
377+
#endif
378+
362379
// Convenient helper functions to get a span of any vector, regardless
363380
// of whether it is null or not (the field is not set).
364381
template <class U>
@@ -377,6 +394,23 @@ FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span<const U> make_span(
377394
return ptr ? make_span(*ptr) : span<const U>();
378395
}
379396

397+
#if FLATBUFFERS_LITTLEENDIAN
398+
399+
template <class U>
400+
FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span<U> make_structs_span(
401+
Vector<const U*>* ptr) FLATBUFFERS_NOEXCEPT {
402+
return ptr ? make_span(*ptr) : span<U>();
403+
}
404+
405+
template <class U>
406+
FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span<const U> make_structs_span(
407+
const Vector<const U*>* ptr) FLATBUFFERS_NOEXCEPT {
408+
return ptr ? make_span(*ptr) : span<const U>();
409+
}
410+
411+
#endif
412+
413+
380414
// Represent a vector much like the template above, but in this case we
381415
// don't know what the element types are (used with reflection.h).
382416
class VectorOfAny {

0 commit comments

Comments
 (0)