13 #ifndef TINYMPL_STRING_HPP
14 #define TINYMPL_STRING_HPP
16 #include <tinympl/algorithm.hpp>
17 #include <tinympl/sequence.hpp>
38 template<
class T,T ... chars>
53 typedef const T * const_pointer;
59 constexpr
static value_type
at(std::size_t i) {
return c_str()[i];}
62 constexpr
static const_pointer
c_str() {
return v_;}
65 constexpr
static value_type
front() {
return at(0);}
68 constexpr
static value_type
back() {
return at(
size - 1);}
72 using wrap = std::integral_constant<T,t>;
74 template<
class ... Us>
83 template<std::
size_t pos,
class Str>
92 template<std::size_t pos,T ... NewChars>
100 template<std::
size_t pos,std::
size_t count>
115 template<T ... NewChars>
119 template<std::
size_t pos, std::
size_t count>
122 static_assert( pos <= size,
"substr pos out of range ");
123 static_assert( pos + count <= size,
"substr count out of range");
134 template<std::
size_t pos, std::
size_t count,
class Str>
137 static_assert( pos <= size,
"substr pos out of range ");
138 static_assert( pos + count <= size,
"substr count out of range");
150 template<std::size_t pos, std::size_t count, T ... ts>
157 template<
class OtherStr>
163 template<std::
size_t i,std::
size_t count>
166 template<
class Str,
int i, std::
size_t s>
struct find_impl :
168 unguarded_substr<i,Str::size>::type::template
169 compare<Str>::value == 0,
170 std::integral_constant<int, i>,
171 find_impl<Str,i+1,s> >
::type {};
173 template<
class Str,
int s>
struct find_impl<Str, s, s> : std::integral_constant<std::size_t, s> {};
175 template<
class Str,
int i>
struct rfind_impl :
177 unguarded_substr<i,Str::size>::type::template
178 compare<Str>::value == 0,
179 std::integral_constant<std::size_t, i>,
180 rfind_impl<Str,i-1> >
::type {};
182 template<
class Str, std::
size_t s>
struct find_impl< Str, -1, s> : std::integral_constant< std::size_t, s> {};
192 using find = find_impl<Str,0,size>;
205 static constexpr T v_[size + 1] = {chars ... , 0};
215 template<
class T,T ... chars>
216 constexpr T basic_string<T,chars...>::v_ [
size + 1];
222 template<
class T, const T * ptr>
225 template<T ... ts>
struct extract
227 typedef typename std::conditional<
228 ptr[
sizeof ... (ts) ] == 0,
230 extract<ts..., ptr[sizeof ... (ts) ]>
234 using type =
typename extract<>::type;
242 template<const
char * p>
243 using string =
typename make_basic_string<char,p>::type;
254 template<
class ... Args>
258 using check_t = std::is_same<typename U::value_type,T>;
261 "basic_string: unable to rebind when the arguments are not of the same value_type" );
268 template<
class ... Ts>
using rebind =
typename do_rebind<Ts...>
::type;
273 #endif // TINYMPL_STRING_HPP
Determine whether the vector is empty.
Definition: string.hpp:48
Return a new string constructed by replacing count characters starting at pos with the string Str...
Definition: string.hpp:135
Provide a customization points by allowing the user to specialize this class.
Definition: as_sequence.hpp:30
Determines whether every element in the sequence satisfies the given predicate.
Definition: all_of.hpp:31
Return a substring long count starting at position pos.
Definition: string.hpp:120
Construct a basic_string from a constexpr pointer to a null-terminated string.
Definition: string.hpp:223
find_impl< Str, 0, size > find
Return the index of the first character of the first occurrence of the substring Str, or size if Str is not a substring of this string.
Definition: string.hpp:192
basic_string< T, chars...> type
This type.
Definition: string.hpp:51
A vector of values of type T.
Definition: string.hpp:39
Counts the number of elements in a sequence equal to a given one.
Definition: count.hpp:35
Compares two sequences using the given comparator.
Definition: lexicographical_compare.hpp:37
Get the number of elements of a sequence.
Definition: size.hpp:27
static constexpr value_type back()
Return a copy of the last character.
Definition: string.hpp:68
static constexpr value_type front()
Return a copy of the first character.
Definition: string.hpp:65
static constexpr value_type at(std::size_t i)
Get the i-th character.
Definition: string.hpp:59
rfind< basic_string< T, ts...> > rfind_c
Return the index of the first character of the last occurrence of the substring ts..., or size if ts... is not a substring of this string.
Definition: string.hpp:202
The main sequence type.
Definition: sequence.hpp:28
Insert a subsequence into a given sequence at a given position.
Definition: insert.hpp:36
find< basic_string< T, ts...> > find_c
Return the index of the first character of the first occurrence of the substring ts..., or size if ts... is not a substring of this string.
Definition: string.hpp:199
The size of the vector.
Definition: string.hpp:43
static constexpr const_pointer c_str()
Return a pointer to a null-terminated C-style string.
Definition: string.hpp:62
rfind_impl< Str, size > rfind
Return the index of the first character of the last occurrence of the substring Str, or size if Str is not a substring of this string.
Definition: string.hpp:196
Remove a range in a given sequence.
Definition: erase.hpp:35
T value_type
The type of the string characters.
Definition: string.hpp:52