From 7c3c027295cc5f4fc2117de7be1008900e5ec7dd Mon Sep 17 00:00:00 2001 From: cor3ntin Date: Mon, 8 Oct 2018 21:52:01 +0200 Subject: [PATCH] Add missing const on Reference::As<> (#4975) Reference::As<> was needlessly mutable wich made them less safe and harder to use --- include/flatbuffers/flexbuffers.h | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/include/flatbuffers/flexbuffers.h b/include/flatbuffers/flexbuffers.h index 1874859f8..cea9d8eb0 100644 --- a/include/flatbuffers/flexbuffers.h +++ b/include/flatbuffers/flexbuffers.h @@ -591,7 +591,7 @@ class Reference { } } - template T As(); + template T As() const; // Experimental: Mutation functions. // These allow scalars in an already created buffer to be updated in-place. @@ -704,35 +704,35 @@ class Reference { }; // Template specialization for As(). -template<> inline bool Reference::As() { return AsBool(); } +template<> inline bool Reference::As() const { return AsBool(); } -template<> inline int8_t Reference::As() { return AsInt8(); } -template<> inline int16_t Reference::As() { return AsInt16(); } -template<> inline int32_t Reference::As() { return AsInt32(); } -template<> inline int64_t Reference::As() { return AsInt64(); } +template<> inline int8_t Reference::As() const { return AsInt8(); } +template<> inline int16_t Reference::As() const { return AsInt16(); } +template<> inline int32_t Reference::As() const { return AsInt32(); } +template<> inline int64_t Reference::As() const { return AsInt64(); } -template<> inline uint8_t Reference::As() { return AsUInt8(); } -template<> inline uint16_t Reference::As() { return AsUInt16(); } -template<> inline uint32_t Reference::As() { return AsUInt32(); } -template<> inline uint64_t Reference::As() { return AsUInt64(); } +template<> inline uint8_t Reference::As() const { return AsUInt8(); } +template<> inline uint16_t Reference::As() const { return AsUInt16(); } +template<> inline uint32_t Reference::As() const { return AsUInt32(); } +template<> inline uint64_t Reference::As() const { return AsUInt64(); } -template<> inline double Reference::As() { return AsDouble(); } -template<> inline float Reference::As() { return AsFloat(); } +template<> inline double Reference::As() const { return AsDouble(); } +template<> inline float Reference::As() const { return AsFloat(); } -template<> inline String Reference::As() { return AsString(); } -template<> inline std::string Reference::As() { +template<> inline String Reference::As() const { return AsString(); } +template<> inline std::string Reference::As() const { return AsString().str(); } -template<> inline Blob Reference::As() { return AsBlob(); } -template<> inline Vector Reference::As() { return AsVector(); } -template<> inline TypedVector Reference::As() { +template<> inline Blob Reference::As() const { return AsBlob(); } +template<> inline Vector Reference::As() const { return AsVector(); } +template<> inline TypedVector Reference::As() const { return AsTypedVector(); } -template<> inline FixedTypedVector Reference::As() { +template<> inline FixedTypedVector Reference::As() const { return AsFixedTypedVector(); } -template<> inline Map Reference::As() { return AsMap(); } +template<> inline Map Reference::As() const { return AsMap(); } inline uint8_t PackedType(BitWidth bit_width, Type type) { return static_cast(bit_width | (type << 2));