-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Philemon Benner
authored and
Philemon Benner
committed
Dec 4, 2024
1 parent
1fb4ff9
commit 07ae29d
Showing
6 changed files
with
166 additions
and
106 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3c15806bfbd628fa20ac4a01ad021ee2 | ||
14f960f02031a37e658f32f87cd0840f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include <string_view> | ||
#include <optional> | ||
#include <cstdint> | ||
#include <charconv> | ||
|
||
// std::optional wrapper around the from chars interface | ||
|
||
namespace st { | ||
|
||
/** | ||
* @brief std::from_chars wrapper, returning nullopt if from chars reports error | ||
* | ||
* @tparam T | ||
* @param s | ||
* @return std::optional<T> | ||
*/ | ||
template <typename T> | ||
constexpr auto FromChars(std::string_view s) -> std::optional<T> { | ||
T val; | ||
if (std::from_chars(s.data(), s.data() + s.size(), val).ec == std::errc{}) { | ||
return val; | ||
} else { | ||
return std::nullopt; | ||
} | ||
} | ||
|
||
template <> | ||
constexpr auto FromChars<bool>(std::string_view s) -> std::optional<bool> { | ||
return FromChars<uint8_t>(s).transform([](uint8_t val) { return static_cast<bool>(val); }); | ||
} | ||
|
||
} // namespace st |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters