diff --git a/include/dds.hpp b/include/dds.hpp index 9cc0f6a..91178d8 100644 --- a/include/dds.hpp +++ b/include/dds.hpp @@ -1,23 +1,23 @@ #pragma once -#if __cplusplus >= 201703L && defined(DDS_USE_STD_FILESYSTEM) +#include "dds_formats.hpp" + +#if DDS_CPP_17 && defined(DDS_USE_STD_FILESYSTEM) #include namespace fs = std::filesystem; #endif -#if __cplusplus >= 202002L +#if DDS_CPP_20 #include #endif #include #include -#include "dds_formats.hpp" - namespace dds { // Not going to include just for std::max and std::min template -#if __cplusplus >= 202002L +#if DDS_CPP_20 requires std::is_arithmetic_v #endif inline constexpr const T& max(const T& a, const T& b) { @@ -25,7 +25,7 @@ namespace dds { } template -#if __cplusplus >= 202002L +#if DDS_CPP_20 requires std::is_arithmetic_v #endif inline constexpr const T& min(const T& a, const T& b) { @@ -294,7 +294,7 @@ namespace dds { } #endif // #ifdef VK_VERSION_1_0 -#if __cplusplus >= 201703L && defined(DDS_USE_STD_FILESYSTEM) +#if DDS_CPP_17 && defined(DDS_USE_STD_FILESYSTEM) DDS_NO_DISCARD inline dds::ReadResult readFile(const fs::path& filepath, dds::Image* image) { #else DDS_NO_DISCARD inline dds::ReadResult readFile(const std::string& filepath, dds::Image* image) { diff --git a/include/dds_formats.hpp b/include/dds_formats.hpp index ac0faab..73d3272 100644 --- a/include/dds_formats.hpp +++ b/include/dds_formats.hpp @@ -7,15 +7,26 @@ static_cast(char1) | (static_cast(char2) << 8) | (static_cast(char3) << 16) | \ (static_cast(char4) << 24) -#define UNDO_FOUR_CHARACTER_CODE(x, name) \ - std::string name; \ - name.reserve(4); \ - name.push_back(x >> 0); \ - name.push_back(x >> 8); \ - name.push_back(x >> 16); \ - name.push_back(x >> 24); +#define UNDO_FOUR_CHARACTER_CODE(x, name) \ + unsigned char name[4]; \ + name[0] = x >> 0; \ + name[1] = x >> 8; \ + name[2] = x >> 16; \ + name[3] = x >> 24; -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) +#define DDS_CPP_17 1 +#else +#define DDS_CPP_17 0 +#endif + +#if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) +#define DDS_CPP_20 1 +#else +#define DDS_CPP_20 0 +#endif + +#if DDS_CPP_17 #define DDS_NO_DISCARD [[nodiscard]] #else #define DDS_NO_DISCARD @@ -153,7 +164,7 @@ enum DXGI_FORMAT { // clang-format on namespace dds { -#if __cplusplus >= 202002L +#if DDS_CPP_20 template using span = std::span; #else diff --git a/tests/test.cpp b/tests/test.cpp index bbc5095..11d7fe0 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -3,6 +3,7 @@ #include #define DDS_USE_STD_FILESYSTEM 1 +#include #include TEST_CASE("Read DDS and write PPM") {