std::string like compile-time const char* string I want to write a very simple std::string like compile-time const char* string.

I need to work with strings in the compiletime, just like with strings, I implemented basic functions.

class cstring final {
const char* str_;
std::size_t size_;

public:
constexpr cstring(const char* str, std::size_t size, std::size_t prefix = 0, std::size_t suffix = 0) noexcept
    : str_{str + prefix},
        size_{size - prefix - suffix} {}

template &lt;std::size_t N&gt;
constexpr cstring(const char (&amp;str)[N]) noexcept : cstring{str, N - 1, 0, 0} {}

constexpr cstring() noexcept : cstring{nullptr, 0, 0, 0} {}

cstring(const std::string&amp; str) noexcept : cstring{str.data(), str.size(), 0, 0} {}

constexpr cstring(const cstring&amp;) = default;

cstring&amp; operator=(const cstring&amp;) = default;

constexpr std::size_t size() const noexcept { return size_; }

constexpr std::size_t length() const noexcept { return size_; }

constexpr std::size_t max_size() const noexcept {
    return (std::numeric_limits&lt;std::size_t&gt;::max)();
}

constexpr bool empty() const noexcept { return size_ == 0; }

constexpr const char* begin() const noexcept { return str_; }

constexpr const char* end() const noexcept { return str_ + size_; }

constexpr const char* cbegin() const noexcept { return begin(); }

constexpr const char* cend() const noexcept { return end(); }

constexpr const char&amp; operator[](std::size_t i) const { return str_[i]; }

constexpr const char&amp; at(std::size_t i) const {
    return (i &lt; size_) ? str_[i]
                    : (throw std::out_of_range{"cstring::at"}, str_[0]);
}

constexpr const char&amp; front() const { return str_[0]; }

constexpr const char&amp; back() const { return str_[size_ - 1]; }

constexpr const char* data() const noexcept { return str_; }

constexpr cstring remove_prefix(std::size_t n) const {
    return {str_ + n, size_ - n};
}

constexpr cstring add_prefix(std::size_t n) const {
    return {str_ - n, size_ + n};
}

constexpr cstring remove_suffix(std::size_t n) const {
    return {str_, size_ - n};
}

constexpr cstring add_suffix(std::size_t n) const {
    return {str_, size_ + n};
}

constexpr cstring substr(std::size_t pos, std::size_t n) const {
    return {str_ + pos, n};
}

constexpr int compare(cstring other) const {
    return (size_ == other.size_) ? detail::StrCompare(str_, other.str_, size_)
                                : ((size_ &gt; other.size_) ? 1 : -1);
}

friend constexpr bool operator==(cstring lhs, cstring rhs) {
    return lhs.compare(rhs) == 0;
}

friend constexpr bool operator!=(cstring lhs, cstring rhs) {
    return !(lhs == rhs);
}

std::string append(cstring s) const {
    return std::string{str_, size_}.append(s.str_, s.size_);
}

friend std::string operator+(cstring lhs, cstring rhs) {
    return std::string{lhs.str_, lhs.size_} + std::string{rhs.str_, rhs.size_};
}

friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, cstring str) {
    os.write(str.str_, str.size_);
    return os;
}

operator std::string() const { return std::string{str_, size_}; }
};


Note that I use C++11 in my project so I can't use std::string_view.
I would only ever mark polymorphic classes final. For them, there's a potential benefit to balance out the unnaturalness of not being able to inherit.
You should really indent the contents of the class by one step. Though that could possibly be an artifact of only partially adapting to SE's markup.
Consider verifying that prefix and suffix have sensible values, at least in debug-mode (assert()).
The first ctor has sensible defaults for its last two parameters. Why not take advantage of that?
Is there a reason you only accept std::string, instead of generally std::basic_string&lt;char, std::char_traits&lt;char&gt;, AnyAllocator&gt;?
You could use !_size instead of _size == 0. Well, de gustibus.
Your comparison is curious, but at least consistent.
I would suggest conforming to C++17 std::string_view as closely as possible so you can later remove your custom class, and to ease the burden for users.