Skip to content

Commit

Permalink
Workaround MSVC bug; converting C strings to bool (#177)
Browse files Browse the repository at this point in the history
On MSVC passing 'const char*' assigns a 'bool' to std::variant instead
of std::string. A non-template overload does prevent this, but will
catch '0' as nullptr.

This can be removed once C++20 is used.
  • Loading branch information
offa committed Mar 10, 2023
1 parent 779de8f commit 4bd80e2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <chrono>
#include <variant>
#include <deque>
#include <type_traits>

#include "influxdb_export.h"

Expand All @@ -55,6 +56,12 @@ namespace influxdb
using FieldValue = std::variant<int, long long int, std::string, double, bool, unsigned int, unsigned long long int>;
Point&& addField(std::string_view name, const FieldValue& value);

template <class T, class = std::enable_if_t<std::is_same_v<T, const char*>, int>>
Point&& addField(std::string_view name, T value)
{
return this->addField(name, std::string{value});
}

/// Generates current timestamp
/// \deprecated Will be removed in v0.8.0
[[deprecated("getCurrentTimestamp() will be removed in v0.8.0")]] static auto getCurrentTimestamp() -> decltype(std::chrono::system_clock::now());
Expand Down

0 comments on commit 4bd80e2

Please sign in to comment.