#pragma once #include #include #include #include using std::cout, std::cin, std::endl, std::size_t; namespace mipt { class StringView { private: const char* mpData; size_t mSize; public: StringView() {; mSize = 0; mpData = nullptr; } StringView(const StringView& str) { mSize = str.mSize; mpData = str.mpData; } StringView(const mipt::String& s) { mSize = s.getSize(); mpData = s.cStr(); } StringView(const char* s) { mpData = s; mSize = strlen(s); } const char& at(size_t i) { if (i >= mSize) { throw std::out_of_range("Error! Index is out of bounds."); std::exit(1); } return mpData[i]; } const char& operator[](size_t i) { return mpData[i]; } size_t size() { return mSize; } }; } std::ostream& operator<<(std::ostream& out, mipt::StringView sv) { size_t size = sv.size(); for (int i = 0; i < size; ++i) out << sv[i]; return out; }