#include #include template Pred> void fun(Pred pred, int value) { std::cout << pred(value) << '\n'; } template size_t findIdx(Container const &cont, size_t from, Value const &value) // requires FindConcept { auto iter = std::find(cont.begin() + from, cont.end(), value); return iter == cont.end() ? cont.size() : iter - cont.begin(); } template concept StdContainer = requires() { typename Container::const_iterator; typename Container::value_type; }; // begin(), end() members -> Container::const_iterator // Container::const_iterator + int -> Container::const_iterator // Container::const_iterator - Container::const_iterator -> int // Predicate(Container::value_type) template concept Iter = requires(Type lhs, Type rhs) { { lhs - rhs } -> std::convertible_to; // or: same_as { lhs + 0 } -> std::same_as; }; #include #include //predicate template concept Find_ifConcept = std::predicate and requires(Container container) { { container.begin() } -> Iter; { container.end() } -> Iter; { container.size() } -> std::same_as; }; template size_t findIdx_if(Container const &cont, size_t from, Predicate const &pred) requires Find_ifConcept { auto iter = std::find_if(cont.begin() + from, cont.end(), pred); return iter == cont.end() ? cont.size() : iter - cont.begin(); } int main() { std::cout << "Index at " << findIdx_if(std::string{ "hello world" }, 0, [&](int ch) { return ch == ' '; } ) << '\n'; int target = 4; fun( [&](int value) { return value == target; }, 4 ); } //=