mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Add ConverterNeedsWriteableRef
This commit is contained in:
		| @@ -140,3 +140,15 @@ TEST_CASE("Custom converter with specialization") { | ||||
|     REQUIRE(doc["value"]["imag"] == 3); | ||||
|   } | ||||
| } | ||||
|  | ||||
| TEST_CASE("ConverterNeedsWriteableRef") { | ||||
|   using namespace ARDUINOJSON_NAMESPACE; | ||||
|   CHECK(ConverterNeedsWriteableRef<int>::value == false); | ||||
|   CHECK(ConverterNeedsWriteableRef<float>::value == false); | ||||
|   CHECK(ConverterNeedsWriteableRef<JsonVariant>::value == true); | ||||
|   CHECK(ConverterNeedsWriteableRef<JsonVariantConst>::value == false); | ||||
|   CHECK(ConverterNeedsWriteableRef<JsonObject>::value == true); | ||||
|   CHECK(ConverterNeedsWriteableRef<JsonObjectConst>::value == false); | ||||
|   CHECK(ConverterNeedsWriteableRef<JsonArray>::value == true); | ||||
|   CHECK(ConverterNeedsWriteableRef<JsonArrayConst>::value == false); | ||||
| } | ||||
|   | ||||
| @@ -310,4 +310,18 @@ inline bool canConvertFromJson(VariantConstRef src, const std::string_view&) { | ||||
|  | ||||
| #endif | ||||
|  | ||||
| template <typename T> | ||||
| struct ConverterNeedsWriteableRef { | ||||
|  protected:  // <- to avoid GCC's "all member functions in class are private" | ||||
|   typedef char Yes[1]; | ||||
|   typedef char No[2]; | ||||
|  | ||||
|   static Yes& probe(T (*f)(VariantRef)); | ||||
|   static No& probe(T (*f)(VariantConstRef)); | ||||
|  | ||||
|  public: | ||||
|   static const bool value = | ||||
|       sizeof(probe(Converter<T>::fromJson)) == sizeof(Yes); | ||||
| }; | ||||
|  | ||||
| }  // namespace ARDUINOJSON_NAMESPACE | ||||
|   | ||||
		Reference in New Issue
	
	Block a user