diff options
author | Hop311 <Hop3114@gmail.com> | 2023-10-17 00:16:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-17 00:16:56 +0200 |
commit | fe319098e49c9841219a9e118a30ebef05eb2c51 (patch) | |
tree | 010ddd76eb8c9d42308f9bba260cc327631dea2c | |
parent | 67bf9236857069090a5f7e00e05c5a3d912c80a7 (diff) | |
parent | c99f8fc82677b1c227a210c38b1496d908a24748 (diff) |
Merge pull request #55 from OpenVicProject/improve_filename_equals
Add constraint to `filename_equals`
-rw-r--r-- | src/openvic-simulation/dataloader/Dataloader.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index 2553b7e..9a34713 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -45,17 +45,22 @@ static constexpr bool path_equals(std::string_view lhs, std::string_view rhs) { #endif } -template<typename LT, typename RT> -static bool filename_equals(const LT& lhs, const RT& rhs) { - std::string left, right; - if constexpr (std::same_as<LT, std::filesystem::path>) - left = lhs.filename().string(); - else left = lhs; - - if constexpr (std::same_as<RT, std::filesystem::path>) - right = rhs.filename().string(); - else right = rhs; - +template<typename T> +concept is_filename = std::same_as<T, std::filesystem::path> || std::convertible_to<T, std::string_view>; + +bool filename_equals(const is_filename auto& lhs, const is_filename auto& rhs) { + auto left = [&lhs] { + if constexpr (std::same_as<std::decay_t<decltype(lhs)>, std::filesystem::path>) + return lhs.filename().string(); + else + return lhs; + }(); + auto right = [&rhs] { + if constexpr (std::same_as<std::decay_t<decltype(rhs)>, std::filesystem::path>) + return rhs.filename().string(); + else + return rhs; + }(); return path_equals(left, right); } |