From 2c8c0ab45ecaffa65b41e894e52f21afb18b4f43 Mon Sep 17 00:00:00 2001 From: blankie Date: Fri, 12 May 2023 17:28:28 +0700 Subject: [PATCH] Check for consteval support --- routes/css.cpp | 4 ++++ thirdparty/FastHash.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/routes/css.cpp b/routes/css.cpp index 57d1ec9..31b9958 100644 --- a/routes/css.cpp +++ b/routes/css.cpp @@ -134,7 +134,11 @@ static const constexpr char css[] = R"EOF( )EOF"; #define CSS_LEN sizeof(css) / sizeof(css[0]) - 1 +#ifdef __cpp_consteval const uint64_t css_hash = FastHashConstEval(css, CSS_LEN, 0); +#else +const uint64_t css_hash = FastHash(css, CSS_LEN, 0); +#endif void css_route(const httplib::Request& req, httplib::Response& res) { res.set_header("ETag", std::string(1, '"') + std::to_string(css_hash) + '"'); diff --git a/thirdparty/FastHash.h b/thirdparty/FastHash.h index 9771eb7..f6b5815 100644 --- a/thirdparty/FastHash.h +++ b/thirdparty/FastHash.h @@ -39,6 +39,8 @@ #pragma once +#include + // Compression function for Merkle-Damgard construction. // This function is generated using the framework provided. //#define mix(h) ({ @@ -75,6 +77,8 @@ constexpr uint64_t FastHash(const char* str, size_t size, uint64_t seed/*, uint6 return mix(h); } +#ifdef __cpp_consteval consteval uint64_t FastHashConstEval(const char* str, size_t size, uint64_t seed) { return FastHash(str, size, seed); } +#endif