lg2: conversion: support std::filesystem::path natively
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ied02e149fd471e25ef1a07f05e437204d2d770cc
diff --git a/lib/include/phosphor-logging/lg2/conversion.hpp b/lib/include/phosphor-logging/lg2/conversion.hpp
index 5f6c298..9788b1a 100644
--- a/lib/include/phosphor-logging/lg2/conversion.hpp
+++ b/lib/include/phosphor-logging/lg2/conversion.hpp
@@ -2,6 +2,7 @@
#include <concepts>
#include <cstddef>
+#include <filesystem>
#include <phosphor-logging/lg2/flags.hpp>
#include <phosphor-logging/lg2/header.hpp>
#include <phosphor-logging/lg2/level.hpp>
@@ -25,7 +26,9 @@
*/
template <typename T>
concept string_like_type =
- std::constructible_from<std::string_view, T> && !std::same_as<nullptr_t, T>;
+ (std::constructible_from<std::string_view, T> ||
+ std::same_as<std::filesystem::path,
+ std::decay_t<T>>)&&!std::same_as<nullptr_t, T>;
/** Concept to determine if an item acts like a pointer.
*
@@ -181,6 +184,7 @@
// Utiilty to handle conversion to a 'const char*' depending on V:
// - 'const char*' and similar use static cast.
+ // - 'std::filesystem::path' use c_str() function.
// - 'std::string' and 'std::string_view' use data() function.
auto str_data = [](V&& v) {
if constexpr (std::is_same_v<const char*, std::decay_t<V>> ||
@@ -188,6 +192,11 @@
{
return static_cast<const char*>(v);
}
+ else if constexpr (std::is_same_v<std::filesystem::path,
+ std::decay_t<V>>)
+ {
+ return v.c_str();
+ }
else
{
return v.data();