Switch to C++20

This commit is contained in:
Georg Hagen
2024-06-21 11:57:53 +02:00
parent ca3985cd68
commit 299040ecaf
7 changed files with 28 additions and 12 deletions

View File

@@ -42,7 +42,7 @@ else()
endif() endif()
FilterPlatformPaths(sources) FilterPlatformPaths(sources)
SetWarningSettings(openVulkanoCpp) SetWarningSettings(openVulkanoCpp)
set_property(TARGET openVulkanoCpp PROPERTY CXX_STANDARD 17) set_property(TARGET openVulkanoCpp PROPERTY CXX_STANDARD 20)
target_sources(openVulkanoCpp PRIVATE ${sources}) target_sources(openVulkanoCpp PRIVATE ${sources})
target_include_directories(openVulkanoCpp PUBLIC openVulkanoCpp) target_include_directories(openVulkanoCpp PUBLIC openVulkanoCpp)

View File

@@ -26,7 +26,7 @@ namespace OpenVulkano
ComponentDecodeHolder(const std::string_view& versionStr) ComponentDecodeHolder(const std::string_view& versionStr)
{ {
if (versionStr.empty()) return; if (versionStr.empty()) return;
int offset = 0; size_t offset = 0;
if (versionStr[0] == 'v' || versionStr[0] == 'V') if (versionStr[0] == 'v' || versionStr[0] == 'V')
{ {
offset++; offset++;
@@ -54,7 +54,7 @@ namespace OpenVulkano
return tmp; return tmp;
} }
static void ReadVersionComponents(std::vector<uint32_t>& comps, const std::string_view& versionStr, int& offset) static void ReadVersionComponents(std::vector<uint32_t>& comps, const std::string_view& versionStr, size_t& offset)
{ {
do do
{ {
@@ -66,7 +66,7 @@ namespace OpenVulkano
} while(versionStr.size() > offset); } while(versionStr.size() > offset);
} }
static void ReadTagComponents(std::vector<std::string>& tags, const std::string_view& versionStr, int& offset) static void ReadTagComponents(std::vector<std::string>& tags, const std::string_view& versionStr, size_t& offset)
{ {
do do
{ {
@@ -88,11 +88,11 @@ namespace OpenVulkano
} }
} }
Version::Version(uint32_t major, uint32_t minor, uint32_t patch, uint32_t build) Version::Version(uint32_t major, uint32_t minor, uint32_t patch, const uint32_t build)
: m_versionComponents(build ? std::initializer_list<uint32_t>{major, minor, patch, build} : std::initializer_list<uint32_t>{major, minor, patch}) : m_versionComponents(build ? std::initializer_list<uint32_t>{major, minor, patch, build} : std::initializer_list<uint32_t>{major, minor, patch})
, m_buildNumber(build) , m_buildNumber(build)
#if (__cplusplus >= 202002L) #if (__cplusplus >= 202002L)
, m_versionString(std::format(build ? "v{}.{}.{}.{}" : "v{}.{}.{}", major, minor, patch, build)) , m_versionString(std::format("v{}.{}.{}.{}", major, minor, patch, build))
#else #else
, m_versionString("v" + std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch) + (build ? "." + std::to_string(build) : "")) , m_versionString("v" + std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch) + (build ? "." + std::to_string(build) : ""))
#endif #endif

View File

@@ -174,7 +174,7 @@ namespace OpenVulkano
fpsTimer = 0; fpsTimer = 0;
if (window->HasTitle()) if (window->HasTitle())
{ {
window->SetTitle(fmt::format(windowTitleFormat, avgFps, avgFrameTime)); window->SetTitle(fmt::format(fmt::runtime(windowTitleFormat), avgFps, avgFrameTime));
} }
} }
} }

View File

@@ -35,7 +35,7 @@ namespace OpenVulkano
void MultiPartArchiveWriter::StartNewFile() void MultiPartArchiveWriter::StartNewFile()
{ {
m_archives.push_back(m_dir / fmt::format(m_fileNamePattern, m_archiveId++)); m_archives.push_back(m_dir / fmt::format(fmt::runtime(m_fileNamePattern), m_archiveId++));
#ifdef WIN32 #ifdef WIN32
m_writer = std::make_unique<ArchiveWriter>(m_archives.back().string().c_str(), m_archiveConfig, m_logger); m_writer = std::make_unique<ArchiveWriter>(m_archives.back().string().c_str(), m_archiveConfig, m_logger);
#else #else

View File

@@ -171,7 +171,7 @@ template<> struct fmt::formatter<OpenVulkano::ByteSize>
template<typename FormatContext> auto format(const OpenVulkano::ByteSize& bs, FormatContext& ctx) template<typename FormatContext> auto format(const OpenVulkano::ByteSize& bs, FormatContext& ctx)
{ {
return format_to(ctx.out(), "{}", bs.Format()); return fmt::format_to(ctx.out(), "{}", bs.Format());
} }
}; };
#endif #endif

View File

@@ -19,9 +19,24 @@
namespace ImGui namespace ImGui
{ {
template <typename T, typename... Args> template <typename... Args>
IMGUI_API void TextFmt(T&& fmt, const Args &... args) { void TextFmt(const std::string_view& fmt, const Args&... args)
std::string str = fmt::format(std::forward<T>(fmt), args...); {
std::string str = fmt::format(fmt::runtime(fmt), (args)...);
ImGui::TextUnformatted(str.data(), str.data() + str.size());
}
template <typename... Args>
void TextFmt(const std::string_view& fmt, Args&&... args)
{
std::string str = fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...);
ImGui::TextUnformatted(str.data(), str.data() + str.size());
}
template <const char* FMT, typename... Args>
IMGUI_API void TextFmt(Args &&... args)
{
std::string str = fmt::format(FMT, std::forward<Args>(args)...);
ImGui::TextUnformatted(str.data(), str.data() + str.size()); ImGui::TextUnformatted(str.data(), str.data() + str.size());
} }
} }

View File

@@ -7,6 +7,7 @@
#include "DeviceManager.hpp" #include "DeviceManager.hpp"
#include "Device.hpp" #include "Device.hpp"
#include <stdexcept> #include <stdexcept>
#include <sstream>
namespace OpenVulkano::Vulkan namespace OpenVulkano::Vulkan
{ {