/* Copyright 2015, Michele Santullo * This file is part of DoorKeeper. * * DoorKeeper is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * DoorKeeper is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DoorKeeper. If not, see . */ #ifndef id170B0E6C34D14EBA9B92A35977BDBFB3 #define id170B0E6C34D14EBA9B92A35977BDBFB3 #include "doorkeeper/implem/sequence_bt.hpp" #include #include #include namespace dk { namespace bt { template class string; template std::ostream& operator<< ( std::ostream& parStream, const string& parString ); template class string { public: friend std::ostream& operator<< <>( std::ostream& parStream, const string& parString ); constexpr string ( const char* 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; template constexpr string ( Args... ); constexpr const char (&data_arr() const)[S] { return m_data; } constexpr const char* data() const { return m_data; } private: template constexpr string ( const index_seq&, const char* parString ); const char m_data[S]; }; namespace implem { template constexpr string concat ( const index_seq&, const string& parLeft, const string& parRight ) { return string( (I < S - 1 ? parLeft[I] : (I < S + S2 - 2 ? parRight[I - (S - 1)] : '\0'))... ); } } //namespace implem template template constexpr string::string (const index_seq&, const char* parString) : m_data{parString[I]...} { } template inline constexpr string::string (const char* parString) : string(index_range<0, S>(), parString) { } template template inline constexpr string::string (Args... parArgs) : m_data{parArgs...} { } template template 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) { parStream << parString.m_data; return parStream; } template constexpr char string::operator[] (std::size_t parIndex) const { return (parIndex < S ? m_data[parIndex] : throw std::out_of_range("")); } template constexpr string make_string (const char (&parData)[S]) { return string(parData); } } //namespace bt } //namespace dk #endif