matrix_thing/include/raii/static_string.hpp

64 lines
1.8 KiB
C++

/**
This file is a part of rexy's matrix client
Copyright (C) 2019 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RAII_STATIC_STRING_HPP
#define RAII_STATIC_STRING_HPP
#include "raii/string_base.hpp"
namespace raii{
class static_string : public string_base
{
public:
constexpr static_string(void) = default;
template<size_t N>
constexpr static_string(const char(&str)[N]):
string_base(const_cast<char*>(str), N){}
constexpr static_string(const char* str, size_t len):
string_base(const_cast<char*>(str), len){}
static_string(const char* c):
string_base(const_cast<char*>(c), strlen(c)){}
constexpr static_string(const static_string& s):
string_base(s.m_data, s.m_length){}
constexpr static_string(static_string&& s):
string_base(s.m_data, s.m_length){}
~static_string(void) = default;
static_string& operator=(const char* c){
m_data = const_cast<char*>(c);
m_length = strlen(c);
return *this;
}
static_string& operator=(const static_string& s){
m_data = s.m_data;
m_length = s.m_length;
return *this;
}
static_string& operator=(static_string&&) = delete;
};
}
namespace{
inline raii::static_string operator"" _ss(const char* str, size_t len){
return raii::static_string(str, len);
}
}
#endif