|
20 | 20 | along with this program. If not, see <https://www.gnu.org/licenses/>. |
21 | 21 | */ |
22 | 22 |
|
| 23 | +//============================================================= |
| 24 | +#include <string> |
| 25 | +//#include <initializer_list> |
23 | 26 |
|
| 27 | + |
| 28 | +//============================================================= |
| 29 | +// Forward declarations |
| 30 | +template< |
| 31 | + class CharT, |
| 32 | + class TraitsT = std::char_traits<CharT>, |
| 33 | + class AllocatorT = std::allocator<CharT> |
| 34 | +> class CppStringT; //!< The templated base class. Use its specializations instead! |
| 35 | + |
| 36 | +using CppString = CppStringT<char>; //!< Specialization of basic class with template argument 'char' |
| 37 | +using CppWString = CppStringT<wchar_t>; //!< Specialization of basic class with template argument 'wchar_t' |
| 38 | + |
| 39 | + |
| 40 | +//===== CppStringT<> ====================================== |
| 41 | +/** |
| 42 | +* \brief This is the templated base class for all CppString |
| 43 | +* classes. |
| 44 | +* |
| 45 | +* Users should instantiate any specialization of this base class |
| 46 | +* rather than this base class itself: |
| 47 | +* - \see CppString for CppStringT<char>. |
| 48 | +* - \see CppWString for CppStringT<wchar_t>. |
| 49 | +* |
| 50 | +* This base class inherits from std::basic_string<CharT>. As such, |
| 51 | +* it gets direct access to all public methods of its base class. |
| 52 | +* \see https://en.cppreference.com/w/cpp/string/basic_string for |
| 53 | +* a full list of such methods, for instance. |
| 54 | +* |
| 55 | +* You may specialize it by your own with any of the next char |
| 56 | +* types: |
| 57 | +* - char8_t (C++20) |
| 58 | +* - char16_t (C++11) |
| 59 | +* - char32_t (C++11) |
| 60 | +*/ |
| 61 | +template<class CharT, class TraitsT, class AllocatorT> |
| 62 | +class CppStringT : public std::basic_string<CharT> |
| 63 | +{ |
| 64 | +public: |
| 65 | + //--- Wrappers ---------------------------------------- |
| 66 | + using MyBaseClass = std::basic_string<CharT>; |
| 67 | + using size_type = MyBaseClass::size_type; |
| 68 | + |
| 69 | + //--- Constructors ------------------------------------ |
| 70 | + inline CppStringT() : MyBaseClass() {} |
| 71 | + inline CppStringT(const CppStringT& other) : MyBaseClass(other) {} |
| 72 | + inline CppStringT(const CppStringT& other, const AllocatorT& alloc) : MyBaseClass(other, alloc){} |
| 73 | + inline CppStringT(CppStringT&& other) : MyBaseClass(other) {} |
| 74 | + inline CppStringT(CppStringT&& other, const AllocatorT& alloc) : MyBaseClass(other, alloc) {} |
| 75 | + inline CppStringT(MyBaseClass::size_type count, CharT ch) : MyBaseClass(count, ch) {} |
| 76 | + inline CppStringT(const CppStringT& other, size_type pos) : MyBaseClass(other, pos) {} |
| 77 | + inline CppStringT(const CppStringT& other, size_type pos, size_type count) noexcept : MyBaseClass(other, pos, count) {} |
| 78 | + inline CppStringT(const CharT* s) : MyBaseClass(s) {} |
| 79 | + inline CppStringT(const CharT* s, size_type count) : MyBaseClass(s, count) {} |
| 80 | + inline CppStringT(std::initializer_list<CharT> ilist) : MyBaseClass(ilist) {} |
| 81 | + |
| 82 | + template<class InputIt> |
| 83 | + inline CppStringT(InputIt first, InputIt last) : MyBaseClass(first, last) {} |
| 84 | + |
| 85 | + template<class StringViewLike> |
| 86 | + explicit CppStringT(const StringViewLike& svl) : MyBaseClass(svl) {} |
| 87 | + |
| 88 | + template<class StringViewLike> |
| 89 | + CppStringT(const StringViewLike& svl, size_type pos, size_type n) : MyBaseClass(svl, pos, n) {} |
| 90 | + |
| 91 | +protected: |
| 92 | + |
| 93 | + |
| 94 | +private: |
| 95 | + |
| 96 | +}; |
0 commit comments