From b32d1e948b32a8f7607ebc30f10dda903426f63c Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 2 Oct 2015 14:55:46 +0200 Subject: 7.1 --- zen/string_traits.h | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'zen/string_traits.h') diff --git a/zen/string_traits.h b/zen/string_traits.h index 8c4775f4..12a7f87c 100644 --- a/zen/string_traits.h +++ b/zen/string_traits.h @@ -173,10 +173,8 @@ size_t cStringLength(const C* str) //naive implementation seems somewhat faster ++len; return len; } -} - -template ::isStringClass>::Type> inline +template ::isStringClass>::Type> inline const typename GetCharType::Type* strBegin(const S& str) //SFINAE: T must be a "string" { return str.c_str(); @@ -190,18 +188,35 @@ inline const char* strBegin(const StringRef& ref) { return ref.data( inline const wchar_t* strBegin(const StringRef& ref) { return ref.data(); } -template ::isStringClass>::Type> inline +template ::isStringClass>::Type> inline size_t strLength(const S& str) //SFINAE: T must be a "string" { return str.length(); } -inline size_t strLength(const char* str) { return implementation::cStringLength(str); } -inline size_t strLength(const wchar_t* str) { return implementation::cStringLength(str); } +inline size_t strLength(const char* str) { return cStringLength(str); } +inline size_t strLength(const wchar_t* str) { return cStringLength(str); } inline size_t strLength(char) { return 1; } inline size_t strLength(wchar_t) { return 1; } inline size_t strLength(const StringRef& ref) { return ref.length(); } inline size_t strLength(const StringRef& ref) { return ref.length(); } } + +template inline +auto strBegin(S&& str) -> const typename GetCharType::Type* +{ + static_assert(IsStringLike::value, ""); + return implementation::strBegin(std::forward(str)); +} + + +template inline +size_t strLength(S&& str) +{ + static_assert(IsStringLike::value, ""); + return implementation::strLength(std::forward(str)); +} +} + #endif //STRING_TRAITS_HEADER_813274321443234 -- cgit