Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
StringRef.hpp
Go to the documentation of this file.
1#pragma once
2#include <memory>
3#include <string_view>
4#include <string>
5
6namespace Thoth::NJson {
7 struct StringRef {
8 std::string_view str;
9
10 StringRef() noexcept = default;
11 StringRef(StringRef&&) noexcept = default;
12 StringRef(const StringRef&) = default;
13 StringRef(const std::string& other);
14 StringRef(std::string_view other, std::shared_ptr<std::string> _data);
15
16 // NOLINTNEXTLINE(*)
17 operator std::string_view() const noexcept;
18 operator std::string() const noexcept;
19
20
21 StringRef& operator=(StringRef&&) noexcept = default;
22 StringRef& operator=(const StringRef&) = default;
23
24 bool operator==(const StringRef&) const;
25
26 private:
27 std::shared_ptr<std::string> _data;
28 // it will keep the buffer alive despite everything.
29 // TODO: FUTURE: `std::shared_ptr<std::string>` causes double allocation, change it later.
30 // ? change to std::pair<std::string_view, const std::shared_ptr<std::string>>?
31 };
32}
33
34#include <Thoth/NJson/StringRef.tpp>
Definition Definitions.hpp:19
Definition StringRef.hpp:7
operator std::string_view() const noexcept
StringRef() noexcept=default
std::string_view str
Definition StringRef.hpp:8