Removal of support for FLATBUFFERS_CPP98_STL (#6918)
authorWouter van Oortmerssen <aardappel@gmail.com>
Fri, 12 Nov 2021 22:01:11 +0000 (14:01 -0800)
committerGitHub <noreply@github.com>
Fri, 12 Nov 2021 22:01:11 +0000 (14:01 -0800)
* Removal of support for FLATBUFFERS_CPP98_STL

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

* Also removed vector_data

29 files changed:
android/app/build.gradle
include/flatbuffers/base.h
include/flatbuffers/detached_buffer.h
include/flatbuffers/flatbuffer_builder.h
include/flatbuffers/flatbuffers.h
include/flatbuffers/flexbuffers.h
include/flatbuffers/idl.h
include/flatbuffers/reflection.h
include/flatbuffers/registry.h
include/flatbuffers/stl_emulation.h
include/flatbuffers/util.h
include/flatbuffers/vector.h
include/flatbuffers/vector_downward.h
samples/monster_generated.h
src/code_generators.cpp
src/idl_gen_cpp.cpp
src/idl_gen_csharp.cpp
src/idl_gen_java.cpp
src/idl_gen_kotlin.cpp
src/idl_parser.cpp
src/reflection.cpp
src/util.cpp
tests/cpp17/generated_cpp17/monster_test_generated.h
tests/monster_test_generated.h
tests/namespace_test/namespace_test1_generated.h
tests/test.cpp
tests/test_assert.h
tests/test_builder.cpp
tests/test_builder.h

index f72f21f..dba6624 100644 (file)
@@ -101,16 +101,6 @@ android {
 
   flavorDimensions "stl-variant"
   productFlavors {
-    stlport {
-      dimension "stl-variant"
-      applicationIdSuffix ".stlport"
-      versionNameSuffix "-stlport"
-      externalNativeBuild {
-        ndkBuild {
-          arguments "APP_STL=stlport_static"
-        }
-      }
-    }
     gnustl {
       dimension "stl-variant"
       applicationIdSuffix ".gnustl"
index f1eb312..15c89b1 100644 (file)
   #include <unistd.h>
 #endif
 
-#ifdef _STLPORT_VERSION
-  #define FLATBUFFERS_CPP98_STL
-#endif
-
 #ifdef __ANDROID__
   #include <android/api-level.h>
 #endif
index 9d00029..760a088 100644 (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_
\ No newline at end of file
+#endif  // FLATBUFFERS_DETACHED_BUFFER_H_
index 5aa358f..324b0c3 100644 (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_
\ No newline at end of file
+#endif  // FLATBUFFERS_VECTOR_DOWNWARD_H_
index 509edd8..306401d 100644 (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.
index 6ac698d..3c85b79 100644 (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_;
index 3ee02a9..bb08806 100644 (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;
index fa2cf31..cb3ec9a 100644 (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*(); }
 
index 563d620..e8bb8f5 100644 (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;
index 2697a0a..75d13b2 100644 (file)
 #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>.
   #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;
-    }
-
-    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;
+      return std::unique_ptr<T>::operator=(p);
     }
-
-   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>
index edbee64..020a060 100644 (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) {
index 820c59c..f8a5d88 100644 (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).
index d507134..8088b10 100644 (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_
\ No newline at end of file
+#endif  // FLATBUFFERS_VECTOR_DOWNWARD_H_
index 50c1ff1..df956e1 100644 (file)
@@ -120,7 +120,6 @@ struct EquipmentUnion {
 
   void Reset();
 
-#ifndef FLATBUFFERS_CPP98_STL
   template <typename T>
   void Set(T&& val) {
     using RT = typename std::remove_reference<T>::type;
@@ -130,7 +129,6 @@ struct EquipmentUnion {
       value = new RT(std::forward<T>(val));
     }
   }
-#endif  // FLATBUFFERS_CPP98_STL
 
   static void *UnPack(const void *obj, Equipment type, const flatbuffers::resolver_function_t *resolver);
   flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
index aa77e1a..38e3b81 100644 (file)
@@ -60,7 +60,7 @@ void CodeWriter::operator+=(std::string text) {
     // Update the text to everything after the }}.
     text = text.substr(end + 2);
   }
-  if (!text.empty() && string_back(text) == '\\') {
+  if (!text.empty() && text.back() == '\\') {
     text.pop_back();
     ignore_ident_ = true;
     stream_ << text;
index e09bad2..4a37eab 100644 (file)
@@ -1339,7 +1339,6 @@ class CppGenerator : public BaseGenerator {
       code_ += "  void Reset();";
       code_ += "";
       if (!enum_def.uses_multiple_type_instances) {
-        code_ += "#ifndef FLATBUFFERS_CPP98_STL";
         code_ += "  template <typename T>";
         code_ += "  void Set(T&& val) {";
         code_ += "    using RT = typename std::remove_reference<T>::type;";
@@ -1350,7 +1349,6 @@ class CppGenerator : public BaseGenerator {
         code_ += "      value = new RT(std::forward<T>(val));";
         code_ += "    }";
         code_ += "  }";
-        code_ += "#endif  // FLATBUFFERS_CPP98_STL";
         code_ += "";
       }
       code_ += "  " + UnionUnPackSignature(enum_def, true) + ";";
index d481a19..dd023bc 100644 (file)
 #include "flatbuffers/idl.h"
 #include "flatbuffers/util.h"
 
-#if defined(FLATBUFFERS_CPP98_STL)
-#  include <cctype>
-#endif  // defined(FLATBUFFERS_CPP98_STL)
-
 namespace flatbuffers {
 
 static TypedFloatConstantGenerator CSharpFloatGen("Double.", "Single.", "NaN",
index 0befb18..01dce4a 100644 (file)
 #include "flatbuffers/idl.h"
 #include "flatbuffers/util.h"
 
-#if defined(FLATBUFFERS_CPP98_STL)
-#  include <cctype>
-#endif  // defined(FLATBUFFERS_CPP98_STL)
-
 namespace flatbuffers {
 namespace java {
 
index 511e1b7..3c9377f 100644 (file)
@@ -23,9 +23,6 @@
 #include "flatbuffers/flatbuffers.h"
 #include "flatbuffers/idl.h"
 #include "flatbuffers/util.h"
-#if defined(FLATBUFFERS_CPP98_STL)
-#  include <cctype>
-#endif  // defined(FLATBUFFERS_CPP98_STL)
 
 namespace flatbuffers {
 
index 328d8dc..4e18e19 100644 (file)
@@ -1627,7 +1627,7 @@ CheckedError Parser::ParseArray(Value &array) {
   auto length = array.type.fixed_length;
   uoffset_t count = 0;
   auto err = ParseVectorDelimiters(count, [&](uoffset_t &) -> CheckedError {
-    vector_emplace_back(&stack, Value());
+    stack.emplace_back(Value());
     auto &val = stack.back();
     val.type = type;
     if (IsStruct(type)) {
@@ -3319,7 +3319,7 @@ CheckedError Parser::DoParse(const char *source, const char **include_paths,
       ECHECK(ParseProtoDecl());
     } else if (IsIdent("native_include")) {
       NEXT();
-      vector_emplace_back(&native_included_files_, attribute_);
+      native_included_files_.emplace_back(attribute_);
       EXPECT(kTokenStringConstant);
       EXPECT(';');
     } else if (IsIdent("include") || (opts.proto_mode && IsIdent("import"))) {
index 2dedcb4..8ab0dc3 100644 (file)
@@ -180,7 +180,7 @@ class ResizeContext {
                 std::vector<uint8_t> *flatbuf,
                 const reflection::Object *root_table = nullptr)
       : schema_(schema),
-        startptr_(vector_data(*flatbuf) + start),
+        startptr_(flatbuf->data() + start),
         delta_(delta),
         buf_(*flatbuf),
         dag_check_(flatbuf->size() / sizeof(uoffset_t), false) {
@@ -188,8 +188,8 @@ class ResizeContext {
     delta_ = (delta_ + mask) & ~mask;
     if (!delta_) return;  // We can't shrink by less than largest_scalar_t.
     // Now change all the offsets by delta_.
-    auto root = GetAnyRoot(vector_data(buf_));
-    Straddle<uoffset_t, 1>(vector_data(buf_), root, vector_data(buf_));
+    auto root = GetAnyRoot(buf_.data());
+    Straddle<uoffset_t, 1>(buf_.data(), root, buf_.data());
     ResizeTable(root_table ? *root_table : *schema.root_table(), root);
     // We can now add or remove bytes at start.
     if (delta_ > 0)
@@ -217,7 +217,7 @@ class ResizeContext {
   // will straddle and which won't.
   uint8_t &DagCheck(const void *offsetloc) {
     auto dag_idx = reinterpret_cast<const uoffset_t *>(offsetloc) -
-                   reinterpret_cast<const uoffset_t *>(vector_data(buf_));
+                   reinterpret_cast<const uoffset_t *>(buf_.data());
     return dag_check_[dag_idx];
   }
 
@@ -309,19 +309,19 @@ void SetString(const reflection::Schema &schema, const std::string &val,
                const reflection::Object *root_table) {
   auto delta = static_cast<int>(val.size()) - static_cast<int>(str->size());
   auto str_start = static_cast<uoffset_t>(
-      reinterpret_cast<const uint8_t *>(str) - vector_data(*flatbuf));
+      reinterpret_cast<const uint8_t *>(str) - flatbuf->data());
   auto start = str_start + static_cast<uoffset_t>(sizeof(uoffset_t));
   if (delta) {
     // Clear the old string, since we don't want parts of it remaining.
-    memset(vector_data(*flatbuf) + start, 0, str->size());
+    memset(flatbuf->data() + start, 0, str->size());
     // Different size, we must expand (or contract).
     ResizeContext(schema, start, delta, flatbuf, root_table);
     // Set the new length.
-    WriteScalar(vector_data(*flatbuf) + str_start,
+    WriteScalar(flatbuf->data() + str_start,
                 static_cast<uoffset_t>(val.size()));
   }
   // Copy new data. Safe because we created the right amount of space.
-  memcpy(vector_data(*flatbuf) + start, val.c_str(), val.size() + 1);
+  memcpy(flatbuf->data() + start, val.c_str(), val.size() + 1);
 }
 
 uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize,
@@ -331,7 +331,7 @@ uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize,
   auto delta_elem = static_cast<int>(newsize) - static_cast<int>(num_elems);
   auto delta_bytes = delta_elem * static_cast<int>(elem_size);
   auto vec_start =
-      reinterpret_cast<const uint8_t *>(vec) - vector_data(*flatbuf);
+      reinterpret_cast<const uint8_t *>(vec) - flatbuf->data();
   auto start = static_cast<uoffset_t>(vec_start + sizeof(uoffset_t) +
                                       elem_size * num_elems);
   if (delta_bytes) {
@@ -339,16 +339,16 @@ uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize,
       // Clear elements we're throwing away, since some might remain in the
       // buffer.
       auto size_clear = -delta_elem * elem_size;
-      memset(vector_data(*flatbuf) + start - size_clear, 0, size_clear);
+      memset(flatbuf->data() + start - size_clear, 0, size_clear);
     }
     ResizeContext(schema, start, delta_bytes, flatbuf, root_table);
-    WriteScalar(vector_data(*flatbuf) + vec_start, newsize);  // Length field.
+    WriteScalar(flatbuf->data() + vec_start, newsize);  // Length field.
     // Set new elements to 0.. this can be overwritten by the caller.
     if (delta_elem > 0) {
-      memset(vector_data(*flatbuf) + start, 0, delta_elem * elem_size);
+      memset(flatbuf->data() + start, 0, delta_elem * elem_size);
     }
   }
-  return vector_data(*flatbuf) + start;
+  return flatbuf->data() + start;
 }
 
 const uint8_t *AddFlatBuffer(std::vector<uint8_t> &flatbuf,
@@ -363,7 +363,7 @@ const uint8_t *AddFlatBuffer(std::vector<uint8_t> &flatbuf,
   // Insert the entire FlatBuffer minus the root pointer.
   flatbuf.insert(flatbuf.end(), newbuf + sizeof(uoffset_t), newbuf + newlen);
   auto root_offset = ReadScalar<uoffset_t>(newbuf) - sizeof(uoffset_t);
-  return vector_data(flatbuf) + insertion_point + root_offset;
+  return flatbuf.data() + insertion_point + root_offset;
 }
 
 void CopyInline(FlatBufferBuilder &fbb, const reflection::Field &fielddef,
index 1a2b5f0..0da2db6 100644 (file)
@@ -158,7 +158,7 @@ std::string ConCatPathFileName(const std::string &path,
                                const std::string &filename) {
   std::string filepath = path;
   if (filepath.length()) {
-    char &filepath_last_character = string_back(filepath);
+    char &filepath_last_character = filepath.back();
     if (filepath_last_character == kPathSeparatorWindows) {
       filepath_last_character = kPathSeparator;
     } else if (filepath_last_character != kPathSeparator) {
@@ -274,7 +274,7 @@ ClassicLocale ClassicLocale::instance_;
 std::string RemoveStringQuotes(const std::string &s) {
   auto ch = *s.c_str();
   return ((s.size() >= 2) && (ch == '\"' || ch == '\'') &&
-          (ch == string_back(s)))
+          (ch == s.back()))
              ? s.substr(1, s.length() - 2)
              : s;
 }
index ee2e86c..430d7aa 100644 (file)
@@ -229,7 +229,6 @@ struct AnyUnion {
 
   void Reset();
 
-#ifndef FLATBUFFERS_CPP98_STL
   template <typename T>
   void Set(T&& val) {
     using RT = typename std::remove_reference<T>::type;
@@ -239,7 +238,6 @@ struct AnyUnion {
       value = new RT(std::forward<T>(val));
     }
   }
-#endif  // FLATBUFFERS_CPP98_STL
 
   static void *UnPack(const void *obj, Any type, const flatbuffers::resolver_function_t *resolver);
   flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
@@ -342,7 +340,6 @@ struct AnyUniqueAliasesUnion {
 
   void Reset();
 
-#ifndef FLATBUFFERS_CPP98_STL
   template <typename T>
   void Set(T&& val) {
     using RT = typename std::remove_reference<T>::type;
@@ -352,7 +349,6 @@ struct AnyUniqueAliasesUnion {
       value = new RT(std::forward<T>(val));
     }
   }
-#endif  // FLATBUFFERS_CPP98_STL
 
   static void *UnPack(const void *obj, AnyUniqueAliases type, const flatbuffers::resolver_function_t *resolver);
   flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
index faa95d9..598dc90 100644 (file)
@@ -259,7 +259,6 @@ struct AnyUnion {
 
   void Reset();
 
-#ifndef FLATBUFFERS_CPP98_STL
   template <typename T>
   void Set(T&& val) {
     using RT = typename std::remove_reference<T>::type;
@@ -269,7 +268,6 @@ struct AnyUnion {
       value = new RT(std::forward<T>(val));
     }
   }
-#endif  // FLATBUFFERS_CPP98_STL
 
   static void *UnPack(const void *obj, Any type, const flatbuffers::resolver_function_t *resolver);
   flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
@@ -401,7 +399,6 @@ struct AnyUniqueAliasesUnion {
 
   void Reset();
 
-#ifndef FLATBUFFERS_CPP98_STL
   template <typename T>
   void Set(T&& val) {
     using RT = typename std::remove_reference<T>::type;
@@ -411,7 +408,6 @@ struct AnyUniqueAliasesUnion {
       value = new RT(std::forward<T>(val));
     }
   }
-#endif  // FLATBUFFERS_CPP98_STL
 
   static void *UnPack(const void *obj, AnyUniqueAliases type, const flatbuffers::resolver_function_t *resolver);
   flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
index b40e407..0fab792 100644 (file)
@@ -79,7 +79,6 @@ struct UnionInNestedNSUnion {
 
   void Reset();
 
-#ifndef FLATBUFFERS_CPP98_STL
   template <typename T>
   void Set(T&& val) {
     using RT = typename std::remove_reference<T>::type;
@@ -89,7 +88,6 @@ struct UnionInNestedNSUnion {
       value = new RT(std::forward<T>(val));
     }
   }
-#endif  // FLATBUFFERS_CPP98_STL
 
   static void *UnPack(const void *obj, UnionInNestedNS type, const flatbuffers::resolver_function_t *resolver);
   flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
index 1c99b51..e5ec7b1 100644 (file)
 #include "flatbuffers/registry.h"
 #include "flatbuffers/util.h"
 
-// clang-format off
-#ifdef FLATBUFFERS_CPP98_STL
-  namespace std {
-    using flatbuffers::unique_ptr;
-  }
-#endif
-// clang-format on
-
 #include "monster_test_generated.h"
 #include "namespace_test/namespace_test1_generated.h"
 #include "namespace_test/namespace_test2_generated.h"
@@ -107,21 +99,11 @@ flatbuffers::DetachedBuffer CreateFlatBufferTest(std::string &buffer) {
   Test tests[] = { Test(10, 20), Test(30, 40) };
   auto testv = builder.CreateVectorOfStructs(tests, 2);
 
-  // clang-format off
-  #ifndef FLATBUFFERS_CPP98_STL
-    // Create a vector of structures from a lambda.
-    auto testv2 = builder.CreateVectorOfStructs<Test>(
-          2, [&](size_t i, Test* s) -> void {
-            *s = tests[i];
-          });
-  #else
-    // Create a vector of structures using a plain old C++ function.
-    auto testv2 = builder.CreateVectorOfStructs<Test>(
-          2, [](size_t i, Test* s, void *state) -> void {
-            *s = (reinterpret_cast<Test*>(state))[i];
-          }, tests);
-  #endif  // FLATBUFFERS_CPP98_STL
-  // clang-format on
+  // Create a vector of structures from a lambda.
+  auto testv2 = builder.CreateVectorOfStructs<Test>(
+        2, [&](size_t i, Test* s) -> void {
+          *s = tests[i];
+        });
 
   // create monster with very few fields set:
   // (same functionality as CreateMonster below, but sets fields manually)
@@ -1071,8 +1053,7 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
   // Get the root.
   // This time we wrap the result from GetAnyRoot in a smartpointer that
   // will keep rroot valid as resizingbuf resizes.
-  auto rroot = flatbuffers::piv(
-      flatbuffers::GetAnyRoot(flatbuffers::vector_data(resizingbuf)),
+  auto rroot = flatbuffers::piv(flatbuffers::GetAnyRoot(resizingbuf.data()),
       resizingbuf);
   SetString(schema, "totally new string", GetFieldS(**rroot, name_field),
             &resizingbuf);
@@ -1117,13 +1098,12 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
   TEST_EQ_STR(rtestarrayofstring->Get(2)->c_str(), "hank");
   // Test integrity of all resize operations above.
   flatbuffers::Verifier resize_verifier(
-      reinterpret_cast<const uint8_t *>(flatbuffers::vector_data(resizingbuf)),
+      reinterpret_cast<const uint8_t *>(resizingbuf.data()),
       resizingbuf.size());
   TEST_EQ(VerifyMonsterBuffer(resize_verifier), true);
 
   // Test buffer is valid using reflection as well
-  TEST_EQ(flatbuffers::Verify(schema, *schema.root_table(),
-                              flatbuffers::vector_data(resizingbuf),
+  TEST_EQ(flatbuffers::Verify(schema, *schema.root_table(), resizingbuf.data(),
                               resizingbuf.size()),
           true);
 
@@ -3000,60 +2980,36 @@ void FlexBuffersTest() {
   // Write the equivalent of:
   // { vec: [ -100, "Fred", 4.0, false ], bar: [ 1, 2, 3 ], bar3: [ 1, 2, 3 ],
   // foo: 100, bool: true, mymap: { foo: "Fred" } }
-  // clang-format off
-  #ifndef FLATBUFFERS_CPP98_STL
-    // It's possible to do this without std::function support as well.
-    slb.Map([&]() {
-       slb.Vector("vec", [&]() {
-        slb += -100;  // Equivalent to slb.Add(-100) or slb.Int(-100);
-        slb += "Fred";
-        slb.IndirectFloat(4.0f);
-        auto i_f = slb.LastValue();
-        uint8_t blob[] = { 77 };
-        slb.Blob(blob, 1);
-        slb += false;
-        slb.ReuseValue(i_f);
-      });
-      int ints[] = { 1, 2, 3 };
-      slb.Vector("bar", ints, 3);
-      slb.FixedTypedVector("bar3", ints, 3);
-      bool bools[] = {true, false, true, false};
-      slb.Vector("bools", bools, 4);
-      slb.Bool("bool", true);
-      slb.Double("foo", 100);
-      slb.Map("mymap", [&]() {
-        slb.String("foo", "Fred");  // Testing key and string reuse.
-      });
+
+  // It's possible to do this without std::function support as well.
+  slb.Map([&]() {
+      slb.Vector("vec", [&]() {
+      slb += -100;  // Equivalent to slb.Add(-100) or slb.Int(-100);
+      slb += "Fred";
+      slb.IndirectFloat(4.0f);
+      auto i_f = slb.LastValue();
+      uint8_t blob[] = { 77 };
+      slb.Blob(blob, 1);
+      slb += false;
+      slb.ReuseValue(i_f);
     });
-    slb.Finish();
-  #else
-    // It's possible to do this without std::function support as well.
-    slb.Map([](flexbuffers::Builder& slb2) {
-       slb2.Vector("vec", [](flexbuffers::Builder& slb3) {
-        slb3 += -100;  // Equivalent to slb.Add(-100) or slb.Int(-100);
-        slb3 += "Fred";
-        slb3.IndirectFloat(4.0f);
-        auto i_f = slb3.LastValue();
-        uint8_t blob[] = { 77 };
-        slb3.Blob(blob, 1);
-        slb3 += false;
-        slb3.ReuseValue(i_f);
-      }, slb2);
-      int ints[] = { 1, 2, 3 };
-      slb2.Vector("bar", ints, 3);
-      slb2.FixedTypedVector("bar3", ints, 3);
-      slb2.Bool("bool", true);
-      slb2.Double("foo", 100);
-      slb2.Map("mymap", [](flexbuffers::Builder& slb3) {
-        slb3.String("foo", "Fred");  // Testing key and string reuse.
-      }, slb2);
-    }, slb);
-    slb.Finish();
-  #endif  // FLATBUFFERS_CPP98_STL
+    int ints[] = { 1, 2, 3 };
+    slb.Vector("bar", ints, 3);
+    slb.FixedTypedVector("bar3", ints, 3);
+    bool bools[] = {true, false, true, false};
+    slb.Vector("bools", bools, 4);
+    slb.Bool("bool", true);
+    slb.Double("foo", 100);
+    slb.Map("mymap", [&]() {
+      slb.String("foo", "Fred");  // Testing key and string reuse.
+    });
+  });
+  slb.Finish();
 
+  // clang-format off
   #ifdef FLATBUFFERS_TEST_VERBOSE
     for (size_t i = 0; i < slb.GetBuffer().size(); i++)
-      printf("%d ", flatbuffers::vector_data(slb.GetBuffer())[i]);
+      printf("%d ", slb.GetBuffer().data()[i]);
     printf("\n");
   #endif
   // clang-format on
@@ -4142,11 +4098,7 @@ int FlatBufferTests() {
 
   std::string rawbuf;
   auto flatbuf1 = CreateFlatBufferTest(rawbuf);
-  #if !defined(FLATBUFFERS_CPP98_STL)
-    auto flatbuf = std::move(flatbuf1);  // Test move assignment.
-  #else
-    auto &flatbuf = flatbuf1;
-  #endif // !defined(FLATBUFFERS_CPP98_STL)
+  auto flatbuf = std::move(flatbuf1);  // Test move assignment.
 
   TriviallyCopyableTest();
 
index 353e3ce..e6140cc 100644 (file)
@@ -73,7 +73,7 @@ struct underlying_of_scalar {
 template<typename T> struct underlying_of_scalar<T, true> {
 // clang-format off
   // There are old compilers without full C++11 support (see stl_emulation.h).
-  #if defined(FLATBUFFERS_TEMPLATES_ALIASES) && !defined(FLATBUFFERS_CPP98_STL)
+  #if defined(FLATBUFFERS_TEMPLATES_ALIASES)
   using type = typename std::underlying_type<T>::type;
   #else
   typedef int64_t type;
index 3a12d79..ae67076 100644 (file)
@@ -9,20 +9,13 @@ struct OwnedAllocator : public flatbuffers::DefaultAllocator {};
 
 class TestHeapBuilder : public flatbuffers::FlatBufferBuilder {
  private:
-  // clang-format off
-  #if !defined(FLATBUFFERS_CPP98_STL)
   TestHeapBuilder(const TestHeapBuilder &);
   TestHeapBuilder &operator=(const TestHeapBuilder &);
-  #endif  // !defined(FLATBUFFERS_CPP98_STL)
-  // clang-format on
 
  public:
   TestHeapBuilder()
       : flatbuffers::FlatBufferBuilder(2048, new OwnedAllocator(), true) {}
 
-  // clang-format off
-  #if !defined(FLATBUFFERS_CPP98_STL)
-  // clang-format on
   TestHeapBuilder(TestHeapBuilder &&other)
       : FlatBufferBuilder(std::move(other)) {}
 
@@ -30,9 +23,6 @@ class TestHeapBuilder : public flatbuffers::FlatBufferBuilder {
     FlatBufferBuilder::operator=(std::move(other));
     return *this;
   }
-  // clang-format off
-  #endif  // !defined(FLATBUFFERS_CPP98_STL)
-  // clang-format on
 };
 
 // This class simulates flatbuffers::grpc::detail::SliceAllocatorMember
@@ -56,18 +46,12 @@ struct GrpcLikeMessageBuilder : private AllocatorMember,
     Swap(other);
   }
 
-  // clang-format off
-  #if !defined(FLATBUFFERS_CPP98_STL)
-  // clang-format on
   GrpcLikeMessageBuilder &operator=(GrpcLikeMessageBuilder &&other) {
     // Construct temporary and swap idiom
     GrpcLikeMessageBuilder temp(std::move(other));
     Swap(temp);
     return *this;
   }
-  // clang-format off
-  #endif  // !defined(FLATBUFFERS_CPP98_STL)
-  // clang-format on
 
   void Swap(GrpcLikeMessageBuilder &other) {
     // No need to swap member_allocator_ because it's stateless.
@@ -155,4 +139,4 @@ void FlatBufferBuilderTest() {
 }
 
 // Link-time check using pointer type.
-void CheckTestGeneratedIsValid(const MyGame::Example::Color &) {}
\ No newline at end of file
+void CheckTestGeneratedIsValid(const MyGame::Example::Color &) {}
index 5555e90..6d97ac0 100644 (file)
@@ -54,9 +54,6 @@ bool release_n_verify(flatbuffers::FlatBufferBuilder &fbb,
 bool release_n_verify(flatbuffers::grpc::MessageBuilder &mbb,
                       const std::string &expected_name, Color color);
 
-// clang-format off
-#if !defined(FLATBUFFERS_CPP98_STL)
-// clang-format on
 // Invokes this function when testing the following Builder types
 // FlatBufferBuilder, TestHeapBuilder, and GrpcLikeMessageBuilder
 template<class Builder>
@@ -78,18 +75,12 @@ void builder_move_assign_after_releaseraw_test(Builder b1) {
   TEST_ASSERT_FUNC(release_n_verify(b1, m2_name(), m2_color()));
   TEST_EQ_FUNC(src.GetSize(), 0);
 }
-// clang-format off
-#endif  // !defined(FLATBUFFERS_CPP98_STL)
-// clang-format on
 
 void builder_move_assign_after_releaseraw_test(
     flatbuffers::grpc::MessageBuilder b1);
 
 template<class DestBuilder, class SrcBuilder = DestBuilder>
 struct BuilderTests {
-  // clang-format off
-  #if !defined(FLATBUFFERS_CPP98_STL)
-  // clang-format on
   static void empty_builder_movector_test() {
     SrcBuilder src;
     size_t src_size = src.GetSize();
@@ -171,9 +162,6 @@ struct BuilderTests {
     TEST_ASSERT_FUNC(release_n_verify(dst, m2_name(), m2_color()));
     TEST_EQ_FUNC(src.GetSize(), 0);
   }
-  // clang-format off
-  #endif  // !defined(FLATBUFFERS_CPP98_STL)
-  // clang-format on
 
   static void builder_swap_before_finish_test(
       bool run = is_same<DestBuilder, SrcBuilder>::value) {
@@ -216,9 +204,6 @@ struct BuilderTests {
   }
 
   static void all_tests() {
-    // clang-format off
-    #if !defined(FLATBUFFERS_CPP98_STL)
-    // clang-format on
     empty_builder_movector_test();
     nonempty_builder_movector_test();
     builder_movector_before_finish_test();
@@ -227,9 +212,6 @@ struct BuilderTests {
     builder_move_assign_after_finish_test();
     builder_move_assign_after_release_test();
     builder_move_assign_after_releaseraw_test(DestBuilder());
-    // clang-format off
-    #endif   // !defined(FLATBUFFERS_CPP98_STL)
-    // clang-format on
     builder_swap_before_finish_test();
     builder_swap_after_finish_test();
   }
@@ -274,9 +256,6 @@ template<class DestBuilder, class SrcBuilder> struct BuilderReuseTests {
     }
   }
 
-  // clang-format off
-  #if !defined(FLATBUFFERS_CPP98_STL)
-  // clang-format on
   static void builder_reusable_after_release_and_move_assign_test(
       TestSelector selector) {
     if (!selector.count(REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN)) { return; }
@@ -311,21 +290,12 @@ template<class DestBuilder, class SrcBuilder> struct BuilderReuseTests {
       TEST_EQ_FUNC(src.GetSize(), 0);
     }
   }
-  // clang-format off
-  #endif  // !defined(FLATBUFFERS_CPP98_STL)
-  // clang-format on
 
   static void run_tests(TestSelector selector) {
     builder_reusable_after_release_test(selector);
     builder_reusable_after_releaseraw_test(selector);
-    // clang-format off
-    #if !defined(FLATBUFFERS_CPP98_STL)
-    // clang-format on
     builder_reusable_after_release_and_move_assign_test(selector);
     builder_reusable_after_releaseraw_and_move_assign_test(selector);
-    // clang-format off
-    #endif  // !defined(FLATBUFFERS_CPP98_STL)
-    // clang-format on
   }
 };