ctpg
ctpg copied to clipboard
string_view buffer
Thanks for your work! I'm enjoying playing with the library.
I found this handy fwiw:
struct sv_buffer
{
public:
constexpr sv_buffer(std::string_view str) : str(str) {}
constexpr sv_buffer(const char *str) : str(str) {}
constexpr auto begin() const { return str.cbegin(); }
constexpr auto end() const { return str.cend(); }
using iterator = std::string_view::const_iterator;
constexpr std::string_view get_view(iterator start, iterator end) const
{
return std::string_view(str.data() + (start - str.begin()),
end - start);
}
private:
std::string_view str;
};
You are welcome! You can prepare a PR with this if you want. Name it string_view_buffer though.
Merged with https://github.com/peter-winter/ctpg/pull/74