22 #ifndef GEARS_STRING_FIND_HPP
23 #define GEARS_STRING_FIND_HPP
25 #include "../meta/alias.hpp"
29 namespace string_find_detail {
33 negator(T t): pred(std::move(t)) {}
34 template<
typename... Args>
35 auto operator()(Args&&... args) -> decltype(!pred(std::forward<Args>(args)...)) {
36 return !pred(std::forward<Args>(args)...);
41 using SizeType =
typename meta::Unqualified<T>::size_type;
55 template<
typename String,
typename UnaryPredicate>
56 inline string_find_detail::SizeType<String>
find_first_of(
const String& str, UnaryPredicate&& pred) {
57 for(
unsigned i = 0; i < str.size(); ++i) {
61 return string_find_detail::SizeType<String>(-1);
75 template<
typename String,
typename UnaryPredicate>
76 inline string_find_detail::SizeType<String>
find_first_not_of(
const String& str, UnaryPredicate&& pred) {
77 return find_first_of(str, string_find_detail::negator<UnaryPredicate>(pred));
91 template<
typename String,
typename UnaryPredicate>
92 inline string_find_detail::SizeType<String>
find_last_of(
const String& str, UnaryPredicate&& pred) {
93 for(
unsigned i = str.size() - 1; i != 0; --i) {
97 return string_find_detail::SizeType<String>(-1);
111 template<
typename String,
typename UnaryPredicate>
112 inline string_find_detail::SizeType<String>
find_last_not_of(
const String& str, UnaryPredicate&& pred) {
113 return find_last_of(str, string_find_detail::negator<UnaryPredicate>(pred));
118 #endif // GEARS_STRING_FIND_HPP