Make StringView and unit types trivial types

This commit is contained in:
Maxime Coste 2017-01-29 13:49:45 +00:00
parent 0cb192921a
commit 753f3a50d1
7 changed files with 25 additions and 11 deletions

View File

@ -47,6 +47,8 @@ namespace
struct Reader
{
public:
Reader(StringView s) : str{s}, pos{}, coord{} {}
[[gnu::always_inline]]
char operator*() const { return str[pos]; }

View File

@ -86,7 +86,7 @@ String real_path(StringView filename)
char buffer[PATH_MAX+1];
StringView existing = filename;
StringView non_existing;
StringView non_existing{};
while (true)
{

View File

@ -516,7 +516,7 @@ bool InsertCompleter::try_complete(Func complete_func)
kak_assert(m_completions.begin <= sels.main().cursor());
m_current_candidate = m_completions.candidates.size();
menu_show();
m_completions.candidates.push_back({sels.buffer().string(m_completions.begin, m_completions.end), ""});
m_completions.candidates.push_back({sels.buffer().string(m_completions.begin, m_completions.end), "", {}});
return true;
}

View File

@ -249,7 +249,7 @@ void register_options()
Vector<String, MemoryDomain::Options>({ "./", "/usr/include" }));
reg.declare_option("completers", "insert mode completers to execute.",
InsertCompleterDescList({
InsertCompleterDesc{ InsertCompleterDesc::Filename },
InsertCompleterDesc{ InsertCompleterDesc::Filename, {} },
InsertCompleterDesc{ InsertCompleterDesc::Word, "all"_str }
}), OptionFlags::None);
reg.declare_option("static_words", "list of words to always consider for insert word completion",

View File

@ -44,7 +44,7 @@ private:
FullMatch = 1 << 5,
};
StringView m_candidate;
StringView m_candidate{};
Flags m_flags = Flags::None;
int m_word_boundary_match_count = 0;
int m_max_index = 0;

View File

@ -211,7 +211,7 @@ private:
class StringView : public StringOps<StringView, const char>
{
public:
constexpr StringView() = default;
StringView() = default;
constexpr StringView(const char* data, ByteCount length)
: m_data{data}, m_length{length} {}
constexpr StringView(const char* data) : m_data{data}, m_length{data ? strlen(data) : 0} {}
@ -248,10 +248,12 @@ public:
ZeroTerminatedString zstr() const { return {begin(), end()}; }
private:
const char* m_data = nullptr;
ByteCount m_length = 0;
const char* m_data;
ByteCount m_length;
};
static_assert(std::is_trivial<StringView>::value, "");
template<typename Type, typename CharType>
inline StringView StringOps<Type, CharType>::substr(ByteCount from, ByteCount length) const
{

View File

@ -13,6 +13,8 @@ template<typename RealType, typename ValueType = int>
class StronglyTypedNumber
{
public:
StronglyTypedNumber() = default;
[[gnu::always_inline]]
explicit constexpr StronglyTypedNumber(ValueType value)
: m_value(value)
@ -124,8 +126,10 @@ protected:
struct LineCount : public StronglyTypedNumber<LineCount, int>
{
LineCount() = default;
[[gnu::always_inline]]
constexpr LineCount(int value = 0) : StronglyTypedNumber<LineCount>(value) {}
constexpr LineCount(int value) : StronglyTypedNumber<LineCount>(value) {}
};
[[gnu::always_inline]]
@ -136,8 +140,10 @@ inline constexpr LineCount operator"" _line(unsigned long long int value)
struct ByteCount : public StronglyTypedNumber<ByteCount, int>
{
ByteCount() = default;
[[gnu::always_inline]]
constexpr ByteCount(int value = 0) : StronglyTypedNumber<ByteCount>(value) {}
constexpr ByteCount(int value) : StronglyTypedNumber<ByteCount>(value) {}
};
[[gnu::always_inline]]
@ -148,8 +154,10 @@ inline constexpr ByteCount operator"" _byte(unsigned long long int value)
struct CharCount : public StronglyTypedNumber<CharCount, int>
{
CharCount() = default;
[[gnu::always_inline]]
constexpr CharCount(int value = 0) : StronglyTypedNumber<CharCount>(value) {}
constexpr CharCount(int value) : StronglyTypedNumber<CharCount>(value) {}
};
[[gnu::always_inline]]
@ -160,8 +168,10 @@ inline constexpr CharCount operator"" _char(unsigned long long int value)
struct ColumnCount : public StronglyTypedNumber<ColumnCount, int>
{
ColumnCount() = default;
[[gnu::always_inline]]
constexpr ColumnCount(int value = 0) : StronglyTypedNumber<ColumnCount>(value) {}
constexpr ColumnCount(int value) : StronglyTypedNumber<ColumnCount>(value) {}
};
[[gnu::always_inline]]