1#ifndef CONVERSION_UTILITIES_STRINGBUILDER_H
2#define CONVERSION_UTILITIES_STRINGBUILDER_H
15template <
class StringType,
class ViewType>
using IsStringViewType = std::is_same<ViewType, std::basic_string_view<typename StringType::value_type>>;
16template <
class StringType,
class CharType>
using IsCharType = std::is_same<typename StringType::value_type, CharType>;
18template <
typename StringType,
typename T>
20 int) ->
decltype(std::declval<StringType &>().append(std::declval<const T &>()), std::declval<const T &>().size(), Traits::Bool<true>{});
21template <
typename StringType,
typename T> Traits::Bool<false> IsStringType(...);
22template <
typename StringType>
void functionTakingConstStringRef(
const StringType &str);
23template <
typename StringType,
typename T>
24auto IsConvertibleToConstStringRef(
int) ->
decltype(functionTakingConstStringRef<StringType>(std::declval<const T &>()), Traits::Bool<true>{});
25template <
typename StringType,
typename T> Traits::Bool<false> IsConvertibleToConstStringRef(...);
26template <
typename StringType,
typename T>
27auto IsConvertibleToConstStringRefViaNative(
28 int) ->
decltype(functionTakingConstStringRef<StringType>(std::declval<const T &>().native()), Traits::Bool<true>{});
29template <
typename StringType,
typename T> Traits::Bool<false> IsConvertibleToConstStringRefViaNative(...);
31template <
typename StringType,
typename StringType2>
32using IsStringType = Traits::All<Traits::Not<IsStringViewType<StringType, StringType2>>,
decltype(Detail::IsStringType<StringType, StringType2>(0))>;
33template <
typename StringType,
typename StringType2>
35 decltype(Detail::IsConvertibleToConstStringRefViaNative<StringType, StringType2>(0))>;
36template <
typename StringType,
typename StringType2>
39 decltype(Detail::IsConvertibleToConstStringRef<StringType, StringType2>(0))>;
41template <
class StringType,
class StringType2, Traits::EnableIf<IsStringType<StringType, StringType2>> * =
nullptr>
47template <
class StringType,
class StringType2, Traits::EnableIf<IsStringType<StringType, StringType2>> * =
nullptr>
53template <
class StringType,
class ConvertibleType, Traits::EnableIf<IsConvertibleToConstStringRef<StringType, ConvertibleType>> * =
nullptr>
59template <
class StringType,
class ConvertibleType, Traits::EnableIf<IsConvertibleToConstStringRef<StringType, ConvertibleType>> * =
nullptr>
65template <
class StringType,
class ConvertibleType, Traits::EnableIf<IsConvertibleToConstStringRefViaNative<StringType, ConvertibleType>> * =
nullptr>
71template <
class StringType,
class ConvertibleType, Traits::EnableIf<IsConvertibleToConstStringRefViaNative<StringType, ConvertibleType>> * =
nullptr>
77template <
class StringType,
class ViewType, Traits::EnableIf<IsStringViewType<StringType, ViewType>> * =
nullptr>
83template <
class StringType,
class ViewType, Traits::EnableIf<IsStringViewType<StringType, ViewType>> * =
nullptr>
89template <
class StringType,
class CharType, Traits::EnableIf<IsCharType<StringType, CharType>> * =
nullptr>
92 return std::char_traits<CharType>::length(
str);
95template <
class StringType,
class CharType, Traits::EnableIf<IsCharType<StringType, CharType>> * =
nullptr>
102 Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>, std::is_integral<IntegralType>,
103 std::is_unsigned<IntegralType>> * =
nullptr>
106 auto size = std::size_t(0
u);
113 Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>, std::is_integral<IntegralType>,
114 std::is_signed<IntegralType>> * =
nullptr>
123template <
class StringType,
typename TupleType, Traits::EnableIf<Traits::IsSpecializationOf<std::decay_t<TupleType>, std::tuple>> * =
nullptr>
140template <
class StringType,
class StringType2, Traits::EnableIf<IsConvertibleToConstStringRefViaNative<StringType, StringType2>> * =
nullptr>
146template <
class StringType,
class StringType2, Traits::EnableIf<IsConvertibleToConstStringRefViaNative<StringType, StringType2>> * =
nullptr>
152template <
class StringType,
class ViewType, Traits::EnableIf<IsStringViewType<StringType, ViewType>> * =
nullptr>
158template <
class StringType,
class ViewType, Traits::EnableIf<IsStringViewType<StringType, ViewType>> * =
nullptr>
164template <
class StringType,
class CharType, Traits::EnableIf<IsCharType<StringType, CharType>> * =
nullptr>
170template <
class StringType,
class CharType, Traits::EnableIf<IsCharType<StringType, CharType>> * =
nullptr>
177 Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>, std::is_integral<IntegralType>,
178 std::is_unsigned<IntegralType>> * =
nullptr>
189 Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>, std::is_integral<IntegralType>,
190 std::is_signed<IntegralType>> * =
nullptr>
204template <
class StringType,
typename TupleType, Traits::EnableIf<Traits::IsSpecializationOf<std::decay_t<TupleType>, std::tuple>> * =
nullptr>
207template <
class StringType,
class Tuple, std::
size_t N>
struct TupleToString {
208 static inline std::size_t precomputeSize(
const Tuple &tuple)
210 return TupleToString<StringType, Tuple, N - 1>::precomputeSize(tuple) + computeTupleElementSize<StringType>(std::get<N - 1>(tuple));
213 static inline void append(
const Tuple &tuple, StringType &str)
215 TupleToString<StringType, Tuple, N - 1>::append(tuple, str);
216 Helper::append(str, std::get<N - 1>(tuple));
221 static inline std::size_t precomputeSize(
const Tuple &tuple)
223 return computeTupleElementSize<StringType>(std::get<0>(tuple));
226 static inline void append(
const Tuple &tuple, StringType &str)
228 Helper::append(str, std::get<0>(tuple));
232template <
class StringType,
typename TupleType, Traits::EnableIf<Traits::IsSpecializationOf<std::decay_t<TupleType>, std::tuple>> *>
239template <
class StringType,
typename TupleType, Traits::EnableIf<Traits::IsSpecializationOf<std::decay_t<TupleType>, std::tuple>> *>
262 return tupleToString(std::tuple<Args &&...>(std::forward<Args>(args)...));
269 Traits::EnableIf<Traits::IsSpecializationOf<Tuple, std::tuple>,
270 Traits::IsSpecializingAnyOf<StringType, std::basic_string, std::basic_string_view>> * =
nullptr>
273 return std::tuple_cat(
lhs, std::tuple<const StringType &>(
rhs));
279template <
class Tuple, Traits::EnableIf<Traits::IsSpecializationOf<Tuple, std::tuple>> * =
nullptr>
282 return std::tuple_cat(
lhs, std::tuple<const char *>(
rhs));
289 Traits::EnableIf<Traits::IsSpecializationOf<Tuple, std::tuple>, std::is_integral<IntegralType>> * =
nullptr>
292 return std::tuple_cat(
lhs, std::tuple<IntegralType>(
rhs));
299 Traits::EnableIfAny<Traits::IsSpecializationOf<StringType, std::basic_string>, Traits::IsSpecializationOf<StringType, std::basic_string_view>>
303 return std::tuple<const StringType &, const StringType &>(
lhs,
rhs);
310 Traits::EnableIfAny<Traits::IsSpecializationOf<StringType, std::basic_string>, Traits::IsSpecializationOf<StringType, std::basic_string_view>>
314 return std::tuple<const char *, const StringType &>(
lhs,
rhs);
321 Traits::EnableIfAny<Traits::IsSpecializationOf<StringType, std::basic_string>, Traits::IsSpecializationOf<StringType, std::basic_string_view>>
325 return std::tuple<const StringType &, const char *>(
lhs,
rhs);
332 Traits::EnableIfAny<Traits::IsSpecializationOf<StringType, std::basic_string>, Traits::IsSpecializationOf<StringType, std::basic_string_view>>
336 return std::tuple<const StringType &, char>(
lhs,
rhs);
343 Traits::EnableIfAny<Traits::IsSpecializationOf<StringType, std::basic_string>, Traits::IsSpecializationOf<StringType, std::basic_string_view>>
347 return std::tuple<char, const StringType &>(
lhs,
rhs);
360 Traits::EnableIf<Traits::IsSpecializationOf<Tuple, std::tuple>,
361 Traits::Any<Traits::IsSpecializationOf<StringType, std::basic_string>, Traits::IsSpecializationOf<StringType, std::basic_string_view>>>
377template <
class Tuple, Traits::EnableIf<Traits::IsSpecializationOf<Tuple, std::tuple>> * =
nullptr>
393 Traits::EnableIf<Traits::IsSpecializationOf<Tuple, std::tuple>, std::is_integral<IntegralType>> * =
nullptr>
#define CPP_UTILITIES_UNUSED(x)
Prevents warnings about unused variables.
Contains all utilities provides by the c++utilities library.
CPP_UTILITIES_EXPORT DateTime operator+(DateTime begin, Period period)
Adds the specified period to the specified date.
constexpr auto operator%(const Tuple &lhs, const StringType &rhs) -> decltype(std::tuple_cat(lhs, std::tuple< const StringType & >(rhs)))
Allows construction of string-tuples via %-operator, eg.
IntegralType stringToNumber(const StringType &string, BaseType base=10)
Converts the given string to an unsigned/signed number assuming string uses the specified base.
StringType argsToString(Args &&...args)
StringType tupleToString(const std::tuple< Args... > &tuple)
Concatenates all strings hold by the specified tuple.