Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Usage:
- // void fn(const string_type& str) {
- // std::cout << str << '\n';
- // }
- struct string_type : std::string_view
- {
- // Takes const char*, std::string, std::string_view
- template <class T, class = std::enable_if_t<
- std::is_constructible_v<std::string_view, const T&>
- >>
- string_type(const T& str) noexcept
- : std::string_view(str)
- { }
- // Takes literal string
- template <size_t N>
- string_type(const char (&str)[N]) noexcept
- : std::string_view(str, N - 1)
- { }
- // Takes QString
- string_type(const QString& str) noexcept
- : qba(str.toLocal8Bit()) {
- this->operator=(std::string_view(qba->data(), qba->size()));
- }
- private:
- std::optional<QByteArray> qba;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement