Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string_view buffer #45

Closed
mjhurd opened this issue Jan 27, 2022 · 2 comments
Closed

string_view buffer #45

mjhurd opened this issue Jan 27, 2022 · 2 comments

Comments

@mjhurd
Copy link

mjhurd commented Jan 27, 2022

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;
};

@peter-winter
Copy link
Owner

You are welcome!
You can prepare a PR with this if you want.
Name it string_view_buffer though.

@peter-winter
Copy link
Owner

Merged with #74

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants