refactor utils
This commit is contained in:
16
utils.h
16
utils.h
@@ -7,13 +7,27 @@
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
|
||||
constexpr std::string_view to_string_view(const std::ranges::subrange<const char *> cs) {
|
||||
namespace utils {
|
||||
|
||||
template<typename T>
|
||||
concept StringLike = requires(const T &t)
|
||||
{
|
||||
{ std::string_view{t} } -> std::convertible_to<std::string_view>;
|
||||
{ t.size() } -> std::convertible_to<size_t>;
|
||||
};
|
||||
|
||||
constexpr std::string_view to_string_view(const std::ranges::subrange<const char *>& cs) {
|
||||
return std::string_view{cs.data(), cs.size()};
|
||||
}
|
||||
|
||||
constexpr bool non_empty(const std::string_view sv) {
|
||||
return !sv.empty();
|
||||
}
|
||||
|
||||
inline std::string read_file(std::string_view path) {
|
||||
std::ifstream input(path.data());
|
||||
std::stringstream buffer;
|
||||
buffer << input.rdbuf();
|
||||
return buffer.str();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user