Removal of support for FLATBUFFERS_CPP98_STL (#6918)

* Removal of support for FLATBUFFERS_CPP98_STL

For context, see https://github.com/google/flatbuffers/issues/6704

* Also removed vector_data
This commit is contained in:
Wouter van Oortmerssen
2021-11-12 14:01:11 -08:00
committed by GitHub
parent 3fab0c6ee4
commit 6748c373be
29 changed files with 119 additions and 545 deletions

View File

@@ -50,10 +50,6 @@
#include <unistd.h>
#endif
#ifdef _STLPORT_VERSION
#define FLATBUFFERS_CPP98_STL
#endif
#ifdef __ANDROID__
#include <android/api-level.h>
#endif

View File

@@ -45,9 +45,6 @@ class DetachedBuffer {
cur_(cur),
size_(sz) {}
// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
DetachedBuffer(DetachedBuffer &&other)
: allocator_(other.allocator_),
own_allocator_(other.own_allocator_),
@@ -57,13 +54,7 @@ class DetachedBuffer {
size_(other.size_) {
other.reset();
}
// clang-format off
#endif // !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
DetachedBuffer &operator=(DetachedBuffer &&other) {
if (this == &other) return *this;
@@ -80,9 +71,6 @@ class DetachedBuffer {
return *this;
}
// clang-format off
#endif // !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
~DetachedBuffer() { destroy(); }
@@ -92,16 +80,10 @@ class DetachedBuffer {
size_t size() const { return size_; }
// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
// These may change access mode, leave these at end of public section
FLATBUFFERS_DELETE_FUNC(DetachedBuffer(const DetachedBuffer &other));
FLATBUFFERS_DELETE_FUNC(
DetachedBuffer &operator=(const DetachedBuffer &other));
// clang-format off
#endif // !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
protected:
Allocator *allocator_;
@@ -129,4 +111,4 @@ class DetachedBuffer {
} // namespace flatbuffers
#endif // FLATBUFFERS_DETACHED_BUFFER_H_
#endif // FLATBUFFERS_DETACHED_BUFFER_H_

View File

@@ -31,9 +31,7 @@
#include "flatbuffers/vector_downward.h"
#include "flatbuffers/verifier.h"
#ifndef FLATBUFFERS_CPP98_STL
# include <functional>
#endif
#include <functional>
namespace flatbuffers {
@@ -96,13 +94,8 @@ class FlatBufferBuilder {
EndianCheck();
}
// clang-format off
/// @brief Move constructor for FlatBufferBuilder.
#if !defined(FLATBUFFERS_CPP98_STL)
FlatBufferBuilder(FlatBufferBuilder &&other)
#else
FlatBufferBuilder(FlatBufferBuilder &other)
#endif // #if !defined(FLATBUFFERS_CPP98_STL)
: buf_(1024, nullptr, false, AlignOf<largest_scalar_t>()),
num_field_loc(0),
max_voffset_(0),
@@ -117,11 +110,7 @@ class FlatBufferBuilder {
// Lack of delegating constructors in vs2010 makes it more verbose than needed.
Swap(other);
}
// clang-format on
// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
/// @brief Move assignment operator for FlatBufferBuilder.
FlatBufferBuilder &operator=(FlatBufferBuilder &&other) {
// Move construct a temporary and swap idiom
@@ -129,9 +118,6 @@ class FlatBufferBuilder {
Swap(temp);
return *this;
}
// clang-format off
#endif // defined(FLATBUFFERS_CPP98_STL)
// clang-format on
void Swap(FlatBufferBuilder &other) {
using std::swap;
@@ -683,8 +669,6 @@ class FlatBufferBuilder {
return Offset<Vector<uint8_t>>(EndVector(v.size()));
}
// clang-format off
#ifndef FLATBUFFERS_CPP98_STL
/// @brief Serialize values returned by a function into a FlatBuffer `vector`.
/// This is a convenience function that takes care of iteration for you.
/// @tparam T The data type of the `std::vector` elements.
@@ -699,8 +683,6 @@ class FlatBufferBuilder {
for (size_t i = 0; i < vector_size; i++) elems[i] = f(i);
return CreateVector(elems);
}
#endif // FLATBUFFERS_CPP98_STL
// clang-format on
/// @brief Serialize values returned by a function into a FlatBuffer `vector`.
/// This is a convenience function that takes care of iteration for you. This
@@ -811,8 +793,6 @@ class FlatBufferBuilder {
return CreateVectorOfNativeStructs(v, len, Pack);
}
// clang-format off
#ifndef FLATBUFFERS_CPP98_STL
/// @brief Serialize an array of structs into a FlatBuffer `vector`.
/// @tparam T The data type of the struct array elements.
/// @param[in] filler A function that takes the current iteration 0..vector_size-1
@@ -830,8 +810,6 @@ class FlatBufferBuilder {
}
return EndVectorOfStructs<T>(vector_size);
}
#endif
// clang-format on
/// @brief Serialize an array of structs into a FlatBuffer `vector`.
/// @tparam T The data type of the struct array elements.
@@ -1198,4 +1176,4 @@ void FlatBufferBuilder::Required(Offset<T> table, voffset_t field) {
} // namespace flatbuffers
#endif // FLATBUFFERS_VECTOR_DOWNWARD_H_
#endif // FLATBUFFERS_VECTOR_DOWNWARD_H_

View File

@@ -92,16 +92,9 @@ struct NativeTable {};
/// if you wish. The resolver does the opposite lookup, for when the object
/// is being serialized again.
typedef uint64_t hash_value_t;
// clang-format off
#ifdef FLATBUFFERS_CPP98_STL
typedef void (*resolver_function_t)(void **pointer_adr, hash_value_t hash);
typedef hash_value_t (*rehasher_function_t)(void *pointer);
#else
typedef std::function<void (void **pointer_adr, hash_value_t hash)>
resolver_function_t;
typedef std::function<hash_value_t (void *pointer)> rehasher_function_t;
#endif
// clang-format on
typedef std::function<void (void **pointer_adr, hash_value_t hash)>
resolver_function_t;
typedef std::function<hash_value_t (void *pointer)> rehasher_function_t;
// Helper function to test if a field is present, using any of the field
// enums in the generated code.

View File

@@ -873,7 +873,7 @@ inline Reference GetRoot(const uint8_t *buffer, size_t size) {
}
inline Reference GetRoot(const std::vector<uint8_t> &buffer) {
return GetRoot(flatbuffers::vector_data(buffer), buffer.size());
return GetRoot(buffer.data(), buffer.size());
}
// Flags that configure how the Builder behaves.
@@ -1069,7 +1069,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
return CreateBlob(data, len, 0, FBT_BLOB);
}
size_t Blob(const std::vector<uint8_t> &v) {
return CreateBlob(flatbuffers::vector_data(v), v.size(), 0, FBT_BLOB);
return CreateBlob(v.data(), v.size(), 0, FBT_BLOB);
}
void Blob(const char *key, const void *data, size_t len) {
@@ -1131,14 +1131,11 @@ class Builder FLATBUFFERS_FINAL_CLASS {
// step automatically when appliccable, and encourage people to write in
// sorted fashion.
// std::sort is typically already a lot faster on sorted data though.
auto dict =
reinterpret_cast<TwoValue *>(flatbuffers::vector_data(stack_) + start);
auto dict = reinterpret_cast<TwoValue *>(stack_.data() + start);
std::sort(dict, dict + len,
[&](const TwoValue &a, const TwoValue &b) -> bool {
auto as = reinterpret_cast<const char *>(
flatbuffers::vector_data(buf_) + a.key.u_);
auto bs = reinterpret_cast<const char *>(
flatbuffers::vector_data(buf_) + b.key.u_);
auto as = reinterpret_cast<const char *>(buf_.data() + a.key.u_);
auto bs = reinterpret_cast<const char *>(buf_.data() + b.key.u_);
auto comp = strcmp(as, bs);
// We want to disallow duplicate keys, since this results in a
// map where values cannot be found.
@@ -1205,7 +1202,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
Vector(elems, len);
}
template<typename T> void Vector(const std::vector<T> &vec) {
Vector(flatbuffers::vector_data(vec), vec.size());
Vector(vec.data(), vec.size());
}
template<typename F> size_t TypedVector(F f) {
@@ -1607,10 +1604,8 @@ class Builder FLATBUFFERS_FINAL_CLASS {
struct KeyOffsetCompare {
explicit KeyOffsetCompare(const std::vector<uint8_t> &buf) : buf_(&buf) {}
bool operator()(size_t a, size_t b) const {
auto stra =
reinterpret_cast<const char *>(flatbuffers::vector_data(*buf_) + a);
auto strb =
reinterpret_cast<const char *>(flatbuffers::vector_data(*buf_) + b);
auto stra = reinterpret_cast<const char *>(buf_->data() + a);
auto strb = reinterpret_cast<const char *>(buf_->data() + b);
return strcmp(stra, strb) < 0;
}
const std::vector<uint8_t> *buf_;
@@ -1621,10 +1616,8 @@ class Builder FLATBUFFERS_FINAL_CLASS {
explicit StringOffsetCompare(const std::vector<uint8_t> &buf)
: buf_(&buf) {}
bool operator()(const StringOffset &a, const StringOffset &b) const {
auto stra = reinterpret_cast<const char *>(
flatbuffers::vector_data(*buf_) + a.first);
auto strb = reinterpret_cast<const char *>(
flatbuffers::vector_data(*buf_) + b.first);
auto stra = reinterpret_cast<const char *>(buf_->data() + a.first);
auto strb = reinterpret_cast<const char *>(buf_->data() + b.first);
return strncmp(stra, strb, (std::min)(a.second, b.second) + 1) < 0;
}
const std::vector<uint8_t> *buf_;

View File

@@ -27,9 +27,7 @@
#include "flatbuffers/hash.h"
#include "flatbuffers/reflection.h"
#if !defined(FLATBUFFERS_CPP98_STL)
# include <functional>
#endif // !defined(FLATBUFFERS_CPP98_STL)
#include <functional>
// This file defines the data types representing a parsed IDL (Interface
// Definition Language) / schema file.
@@ -207,7 +205,7 @@ template<typename T> class SymbolTable {
}
bool Add(const std::string &name, T *e) {
vector_emplace_back(&vec, e);
vec.emplace_back(e);
auto it = dict.find(name);
if (it != dict.end()) return true;
dict[name] = e;

View File

@@ -379,12 +379,12 @@ template<typename T, typename U> class pointer_inside_vector {
public:
pointer_inside_vector(T *ptr, std::vector<U> &vec)
: offset_(reinterpret_cast<uint8_t *>(ptr) -
reinterpret_cast<uint8_t *>(flatbuffers::vector_data(vec))),
reinterpret_cast<uint8_t *>(vec.data())),
vec_(vec) {}
T *operator*() const {
return reinterpret_cast<T *>(
reinterpret_cast<uint8_t *>(flatbuffers::vector_data(vec_)) + offset_);
return reinterpret_cast<T *>(reinterpret_cast<uint8_t *>(vec_.data()) +
offset_);
}
T *operator->() const { return operator*(); }

View File

@@ -104,7 +104,7 @@ class Registry {
}
// Parse schema.
parser->opts = opts_;
if (!parser->Parse(schematext.c_str(), vector_data(include_paths_),
if (!parser->Parse(schematext.c_str(), include_paths_.data(),
schema.path_.c_str())) {
lasterror_ = parser->error_;
return false;

View File

@@ -26,14 +26,6 @@
#include <memory>
#include <limits>
#if defined(_STLPORT_VERSION) && !defined(FLATBUFFERS_CPP98_STL)
#define FLATBUFFERS_CPP98_STL
#endif // defined(_STLPORT_VERSION) && !defined(FLATBUFFERS_CPP98_STL)
#if defined(FLATBUFFERS_CPP98_STL)
#include <cctype>
#endif // defined(FLATBUFFERS_CPP98_STL)
// Detect C++17 compatible compiler.
// __cplusplus >= 201703L - a compiler has support of 'static inline' variables.
#if defined(FLATBUFFERS_USE_STD_OPTIONAL) \
@@ -55,7 +47,7 @@
#endif
#else
// Disable non-trivial ctors if FLATBUFFERS_SPAN_MINIMAL defined.
#if !defined(FLATBUFFERS_TEMPLATES_ALIASES) || defined(FLATBUFFERS_CPP98_STL)
#if !defined(FLATBUFFERS_TEMPLATES_ALIASES)
#define FLATBUFFERS_SPAN_MINIMAL
#else
// Enable implicit construction of a span<T,N> from a std::array<T,N>.
@@ -63,139 +55,32 @@
#endif
#endif // defined(FLATBUFFERS_USE_STD_SPAN)
// This header provides backwards compatibility for C++98 STLs like stlport.
// This header provides backwards compatibility for older versions of the STL.
namespace flatbuffers {
// Retrieve ::back() from a string in a way that is compatible with pre C++11
// STLs (e.g stlport).
inline char& string_back(std::string &value) {
return value[value.length() - 1];
}
inline char string_back(const std::string &value) {
return value[value.length() - 1];
}
// Helper method that retrieves ::data() from a vector in a way that is
// compatible with pre C++11 STLs (e.g stlport).
template <typename T> inline T *vector_data(std::vector<T> &vector) {
// In some debug environments, operator[] does bounds checking, so &vector[0]
// can't be used.
return vector.empty() ? nullptr : &vector[0];
}
template <typename T> inline const T *vector_data(
const std::vector<T> &vector) {
return vector.empty() ? nullptr : &vector[0];
}
template <typename T, typename V>
inline void vector_emplace_back(std::vector<T> *vector, V &&data) {
#if defined(FLATBUFFERS_CPP98_STL)
vector->push_back(data);
#else
vector->emplace_back(std::forward<V>(data));
#endif // defined(FLATBUFFERS_CPP98_STL)
}
#ifndef FLATBUFFERS_CPP98_STL
#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
template <typename T>
using numeric_limits = std::numeric_limits<T>;
#else
template <typename T> class numeric_limits :
public std::numeric_limits<T> {};
#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
template <typename T>
using numeric_limits = std::numeric_limits<T>;
#else
template <typename T> class numeric_limits :
public std::numeric_limits<T> {
public:
// Android NDK fix.
static T lowest() {
return std::numeric_limits<T>::min();
}
};
template <> class numeric_limits<float> :
public std::numeric_limits<float> {
public:
static float lowest() { return -FLT_MAX; }
};
template <> class numeric_limits<double> :
public std::numeric_limits<double> {
public:
static double lowest() { return -DBL_MAX; }
};
template <> class numeric_limits<unsigned long long> {
public:
static unsigned long long min() { return 0ULL; }
static unsigned long long max() { return ~0ULL; }
static unsigned long long lowest() {
return numeric_limits<unsigned long long>::min();
}
};
template <> class numeric_limits<long long> {
public:
static long long min() {
return static_cast<long long>(1ULL << ((sizeof(long long) << 3) - 1));
}
static long long max() {
return static_cast<long long>(
(1ULL << ((sizeof(long long) << 3) - 1)) - 1);
}
static long long lowest() {
return numeric_limits<long long>::min();
}
};
#endif // FLATBUFFERS_CPP98_STL
public std::numeric_limits<T> {};
#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
#ifndef FLATBUFFERS_CPP98_STL
template <typename T> using is_scalar = std::is_scalar<T>;
template <typename T, typename U> using is_same = std::is_same<T,U>;
template <typename T> using is_floating_point = std::is_floating_point<T>;
template <typename T> using is_unsigned = std::is_unsigned<T>;
template <typename T> using is_enum = std::is_enum<T>;
template <typename T> using make_unsigned = std::make_unsigned<T>;
template<bool B, class T, class F>
using conditional = std::conditional<B, T, F>;
template<class T, T v>
using integral_constant = std::integral_constant<T, v>;
template <bool B>
using bool_constant = integral_constant<bool, B>;
using true_type = std::true_type;
using false_type = std::false_type;
#else
// Map C++ TR1 templates defined by stlport.
template <typename T> using is_scalar = std::tr1::is_scalar<T>;
template <typename T, typename U> using is_same = std::tr1::is_same<T,U>;
template <typename T> using is_floating_point =
std::tr1::is_floating_point<T>;
template <typename T> using is_unsigned = std::tr1::is_unsigned<T>;
template <typename T> using is_enum = std::tr1::is_enum<T>;
// Android NDK doesn't have std::make_unsigned or std::tr1::make_unsigned.
template<typename T> struct make_unsigned {
static_assert(is_unsigned<T>::value, "Specialization not implemented!");
using type = T;
};
template<> struct make_unsigned<char> { using type = unsigned char; };
template<> struct make_unsigned<short> { using type = unsigned short; };
template<> struct make_unsigned<int> { using type = unsigned int; };
template<> struct make_unsigned<long> { using type = unsigned long; };
template<>
struct make_unsigned<long long> { using type = unsigned long long; };
template<bool B, class T, class F>
using conditional = std::tr1::conditional<B, T, F>;
template<class T, T v>
using integral_constant = std::tr1::integral_constant<T, v>;
template <bool B>
using bool_constant = integral_constant<bool, B>;
using true_type = bool_constant<true>;
using false_type = bool_constant<false>;
#endif // !FLATBUFFERS_CPP98_STL
template <typename T> using is_scalar = std::is_scalar<T>;
template <typename T, typename U> using is_same = std::is_same<T,U>;
template <typename T> using is_floating_point = std::is_floating_point<T>;
template <typename T> using is_unsigned = std::is_unsigned<T>;
template <typename T> using is_enum = std::is_enum<T>;
template <typename T> using make_unsigned = std::make_unsigned<T>;
template<bool B, class T, class F>
using conditional = std::conditional<B, T, F>;
template<class T, T v>
using integral_constant = std::integral_constant<T, v>;
template <bool B>
using bool_constant = integral_constant<bool, B>;
using true_type = std::true_type;
using false_type = std::false_type;
#else
// MSVC 2010 doesn't support C++11 aliases.
template <typename T> struct is_scalar : public std::is_scalar<T> {};
@@ -215,124 +100,33 @@ inline void vector_emplace_back(std::vector<T> *vector, V &&data) {
typedef bool_constant<false> false_type;
#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
#ifndef FLATBUFFERS_CPP98_STL
#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
template <class T> using unique_ptr = std::unique_ptr<T>;
#else
// MSVC 2010 doesn't support C++11 aliases.
// We're manually "aliasing" the class here as we want to bring unique_ptr
// into the flatbuffers namespace. We have unique_ptr in the flatbuffers
// namespace we have a completely independent implementation (see below)
// for C++98 STL implementations.
template <class T> class unique_ptr : public std::unique_ptr<T> {
public:
unique_ptr() {}
explicit unique_ptr(T* p) : std::unique_ptr<T>(p) {}
unique_ptr(std::unique_ptr<T>&& u) { *this = std::move(u); }
unique_ptr(unique_ptr&& u) { *this = std::move(u); }
unique_ptr& operator=(std::unique_ptr<T>&& u) {
std::unique_ptr<T>::reset(u.release());
return *this;
}
unique_ptr& operator=(unique_ptr&& u) {
std::unique_ptr<T>::reset(u.release());
return *this;
}
unique_ptr& operator=(T* p) {
return std::unique_ptr<T>::operator=(p);
}
};
#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
template <class T> using unique_ptr = std::unique_ptr<T>;
#else
// Very limited implementation of unique_ptr.
// This is provided simply to allow the C++ code generated from the default
// settings to function in C++98 environments with no modifications.
template <class T> class unique_ptr {
public:
typedef T element_type;
unique_ptr() : ptr_(nullptr) {}
explicit unique_ptr(T* p) : ptr_(p) {}
unique_ptr(unique_ptr&& u) : ptr_(nullptr) { reset(u.release()); }
unique_ptr(const unique_ptr& u) : ptr_(nullptr) {
reset(const_cast<unique_ptr*>(&u)->release());
}
~unique_ptr() { reset(); }
unique_ptr& operator=(const unique_ptr& u) {
reset(const_cast<unique_ptr*>(&u)->release());
// MSVC 2010 doesn't support C++11 aliases.
// We're manually "aliasing" the class here as we want to bring unique_ptr
// into the flatbuffers namespace. We have unique_ptr in the flatbuffers
// namespace we have a completely independent implementation (see below)
// for C++98 STL implementations.
template <class T> class unique_ptr : public std::unique_ptr<T> {
public:
unique_ptr() {}
explicit unique_ptr(T* p) : std::unique_ptr<T>(p) {}
unique_ptr(std::unique_ptr<T>&& u) { *this = std::move(u); }
unique_ptr(unique_ptr&& u) { *this = std::move(u); }
unique_ptr& operator=(std::unique_ptr<T>&& u) {
std::unique_ptr<T>::reset(u.release());
return *this;
}
unique_ptr& operator=(unique_ptr&& u) {
reset(u.release());
std::unique_ptr<T>::reset(u.release());
return *this;
}
unique_ptr& operator=(T* p) {
reset(p);
return *this;
return std::unique_ptr<T>::operator=(p);
}
const T& operator*() const { return *ptr_; }
T* operator->() const { return ptr_; }
T* get() const noexcept { return ptr_; }
explicit operator bool() const { return ptr_ != nullptr; }
// modifiers
T* release() {
T* value = ptr_;
ptr_ = nullptr;
return value;
}
void reset(T* p = nullptr) {
T* value = ptr_;
ptr_ = p;
if (value) delete value;
}
void swap(unique_ptr& u) {
T* temp_ptr = ptr_;
ptr_ = u.ptr_;
u.ptr_ = temp_ptr;
}
private:
T* ptr_;
};
template <class T> bool operator==(const unique_ptr<T>& x,
const unique_ptr<T>& y) {
return x.get() == y.get();
}
template <class T, class D> bool operator==(const unique_ptr<T>& x,
const D* y) {
return static_cast<D*>(x.get()) == y;
}
template <class T> bool operator==(const unique_ptr<T>& x, intptr_t y) {
return reinterpret_cast<intptr_t>(x.get()) == y;
}
template <class T> bool operator!=(const unique_ptr<T>& x, decltype(nullptr)) {
return !!x;
}
template <class T> bool operator!=(decltype(nullptr), const unique_ptr<T>& x) {
return !!x;
}
template <class T> bool operator==(const unique_ptr<T>& x, decltype(nullptr)) {
return !x;
}
template <class T> bool operator==(decltype(nullptr), const unique_ptr<T>& x) {
return !x;
}
#endif // !FLATBUFFERS_CPP98_STL
#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES)
#ifdef FLATBUFFERS_USE_STD_OPTIONAL
template<class T>

View File

@@ -145,20 +145,6 @@ template<> inline std::string NumToString<unsigned char>(unsigned char t) {
template<> inline std::string NumToString<char>(char t) {
return NumToString(static_cast<int>(t));
}
#if defined(FLATBUFFERS_CPP98_STL)
template<> inline std::string NumToString<long long>(long long t) {
char buf[21]; // (log((1 << 63) - 1) / log(10)) + 2
snprintf(buf, sizeof(buf), "%lld", t);
return std::string(buf);
}
template<>
inline std::string NumToString<unsigned long long>(unsigned long long t) {
char buf[22]; // (log((1 << 63) - 1) / log(10)) + 1
snprintf(buf, sizeof(buf), "%llu", t);
return std::string(buf);
}
#endif // defined(FLATBUFFERS_CPP98_STL)
// Special versions for floats/doubles.
template<typename T> std::string FloatToString(T t, int precision) {

View File

@@ -43,14 +43,10 @@ template<typename T, typename IT> struct VectorIterator {
return *this;
}
// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
VectorIterator &operator=(VectorIterator &&other) {
data_ = other.data_;
return *this;
}
#endif // !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
bool operator==(const VectorIterator &other) const {
return data_ == other.data_;
@@ -351,7 +347,6 @@ class VectorOfAny {
VectorOfAny &operator=(const VectorOfAny &);
};
#ifndef FLATBUFFERS_CPP98_STL
template<typename T, typename U>
Vector<Offset<T>> *VectorCast(Vector<Offset<U>> *ptr) {
static_assert(std::is_base_of<T, U>::value, "Unrelated types");
@@ -363,7 +358,6 @@ const Vector<Offset<T>> *VectorCast(const Vector<Offset<U>> *ptr) {
static_assert(std::is_base_of<T, U>::value, "Unrelated types");
return reinterpret_cast<const Vector<Offset<T>> *>(ptr);
}
#endif
// Convenient helper function to get the length of any vector, regardless
// of whether it is null or not (the field is not set).

View File

@@ -42,12 +42,7 @@ class vector_downward {
cur_(nullptr),
scratch_(nullptr) {}
// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
vector_downward(vector_downward &&other)
#else
vector_downward(vector_downward &other)
#endif // defined(FLATBUFFERS_CPP98_STL)
// clang-format on
: allocator_(other.allocator_),
own_allocator_(other.own_allocator_),
@@ -67,18 +62,12 @@ class vector_downward {
other.scratch_ = nullptr;
}
// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
vector_downward &operator=(vector_downward &&other) {
// Move construct a temporary and swap idiom
vector_downward temp(std::move(other));
swap(temp);
return *this;
}
// clang-format off
#endif // defined(FLATBUFFERS_CPP98_STL)
// clang-format on
~vector_downward() {
clear_buffer();
@@ -269,4 +258,4 @@ class vector_downward {
} // namespace flatbuffers
#endif // FLATBUFFERS_VECTOR_DOWNWARD_H_
#endif // FLATBUFFERS_VECTOR_DOWNWARD_H_