From d29e83f78d0fabe67dfac99d8444fe7710d23670 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 21 Jul 2018 23:29:55 +0100 Subject: [PATCH] Add a char type template parameter --- include/duckhandy/string_bt.hpp | 53 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/include/duckhandy/string_bt.hpp b/include/duckhandy/string_bt.hpp index 6fe1823..6697579 100644 --- a/include/duckhandy/string_bt.hpp +++ b/include/duckhandy/string_bt.hpp @@ -25,34 +25,35 @@ namespace dhandy { namespace bt { - template + template class string; - template - std::ostream& operator<< ( std::ostream& parStream, const string& parString ); + template + std::basic_ostream& operator<< ( std::basic_ostream& parStream, const string& parString ); - template + template class string { - public: friend std::ostream& operator<< <>( std::ostream& parStream, const string& parString ); - constexpr string ( const char* parString ); + public: + using value_type = Ch; + constexpr string ( const value_type* parString ); constexpr std::size_t size ( void ) const { return S - 1; } template - constexpr string operator+ ( const string& parOther ) const; - constexpr char operator[] ( std::size_t parIndex ) const; + constexpr string operator+ ( const string& parOther ) const; + constexpr value_type operator[] ( std::size_t parIndex ) const; template constexpr string ( Args... ); - constexpr const char (&data_arr() const)[S] { return m_data; } - constexpr const char* data() const { return m_data; } + constexpr const value_type (&data_arr() const)[S] { return m_data; } + constexpr const value_type* data() const { return m_data; } private: template - constexpr string ( const index_seq&, const char* parString ); + constexpr string ( const index_seq&, const value_type* parString ); - const char m_data[S]; + const value_type m_data[S]; }; namespace implem { @@ -65,45 +66,45 @@ namespace dhandy { } //namespace implem - template + template template - constexpr string::string (const index_seq&, const char* parString) : + constexpr string::string (const index_seq&, const value_type* parString) : m_data{parString[I]...} { } - template - inline constexpr string::string (const char* parString) : + template + inline constexpr string::string (const value_type* parString) : string(index_range<0, S>(), parString) { } - template + template template - inline constexpr string::string (Args... parArgs) : + inline constexpr string::string (Args... parArgs) : m_data{parArgs...} { } - template + template template - constexpr inline string string::operator+ (const string& parOther) const { + constexpr inline string string::operator+ (const string& parOther) const { return implem::concat(index_range<0, S + S2 - 1>(), string(m_data), parOther); } - template - inline std::ostream& operator<< (std::ostream& parStream, const string& parString) { + template + inline std::ostream& operator<< (std::ostream& parStream, const string& parString) { parStream << parString.m_data; return parStream; } - template - constexpr char string::operator[] (std::size_t parIndex) const { + template + constexpr auto string::operator[] (std::size_t parIndex) const -> value_type { return (parIndex < S ? m_data[parIndex] : throw std::out_of_range("")); } - template - constexpr string make_string (const char (&parData)[S]) { + template + constexpr string make_string (const Ch (&parData)[S]) { return string(parData); } } //namespace bt