From 0e6f065d1d1bb917e02aa04eb86df4524020a884 Mon Sep 17 00:00:00 2001 From: Manu343726 Date: Wed, 28 Dec 2016 22:26:48 +0100 Subject: [PATCH] [#83] std::string and C string (Const)StringView constructors --- include/siplasplas/constexpr/stringview.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/siplasplas/constexpr/stringview.hpp b/include/siplasplas/constexpr/stringview.hpp index d7eae3f..fb46752 100644 --- a/include/siplasplas/constexpr/stringview.hpp +++ b/include/siplasplas/constexpr/stringview.hpp @@ -27,6 +27,14 @@ class StringView : public ArrayView ArrayView{std::move(arrayView)} {} + constexpr StringView(char* const str) : + ArrayView{str, str + ::cpp::constexp::strlen(str)} + {} + + StringView(std::string& str) : + ArrayView{&str[0], &str[str.size()]} + {} + std::string str() const { /* @@ -65,6 +73,14 @@ class ConstStringView : public ConstArrayView ConstArrayView{std::move(arrayView)} {} + constexpr ConstStringView(const char* str) : + ConstArrayView{str, str + ::cpp::constexp::strlen(str)} + {} + + ConstStringView(const std::string& str) : + ConstArrayView{&str[0], &str[str.size()]} + {} + std::string str() const { /* @@ -90,6 +106,9 @@ class ConstStringView : public ConstArrayView } }; +using StringViews = ArrayView; +using ConstStringViews = ConstArrayView; + } }