Skip to content

Commit

Permalink
[#83] std::string and C string (Const)StringView constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
Manu343726 committed Dec 28, 2016
1 parent b47b173 commit 0e6f065
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/siplasplas/constexpr/stringview.hpp
Expand Up @@ -27,6 +27,14 @@ class StringView : public ArrayView<char>
ArrayView<char>{std::move(arrayView)}
{}

constexpr StringView(char* const str) :
ArrayView<char>{str, str + ::cpp::constexp::strlen(str)}
{}

StringView(std::string& str) :
ArrayView<char>{&str[0], &str[str.size()]}
{}

std::string str() const
{
/*
Expand Down Expand Up @@ -65,6 +73,14 @@ class ConstStringView : public ConstArrayView<char>
ConstArrayView<char>{std::move(arrayView)}
{}

constexpr ConstStringView(const char* str) :
ConstArrayView<char>{str, str + ::cpp::constexp::strlen(str)}
{}

ConstStringView(const std::string& str) :
ConstArrayView<char>{&str[0], &str[str.size()]}
{}

std::string str() const
{
/*
Expand All @@ -90,6 +106,9 @@ class ConstStringView : public ConstArrayView<char>
}
};

using StringViews = ArrayView<const char*>;
using ConstStringViews = ConstArrayView<const char*>;

}

}
Expand Down

0 comments on commit 0e6f065

Please sign in to comment.