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 Nov 2, 2023
1 parent f533f14 commit 5dde088
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 @@ -54,6 +55,12 @@ namespace influxdb
/// Adds field
Point&& addField(std::string_view name, const std::variant<int, long long int, std::string, double>& 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 5dde088

Please sign in to comment.