/* * algorithm.hpp * * Created on: May 28, 2015 * Author: Jan Travnicek */ #ifndef __ALGORITHM_HPP_ #define __ALGORITHM_HPP_ #include <algorithm> #include <functional> namespace ext { template<class InputIt1, class InputIt2, class Compare> bool excludes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp) { while (first2 != last2 && first1 != last1) { if (comp(*first2, *first1)) { ++first2; } else if (comp(*first1, *first2)) { ++first1; } else { return false; } } return true; } template<class InputIt1, class InputIt2> bool excludes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) { return excludes(first1, last1, first2, last2, std::less<decltype(*first1)>()); } template < class ResType, class InType, typename ... Ts, template < typename ... > class ContainerType, class Callback > ContainerType < ResType > transform(const ContainerType < InType, Ts ... > & in, Callback transform ) { ContainerType<ResType> res; std::transform ( in.begin ( ), in.end ( ), std::inserter ( res, res.begin ( ) ), transform ); return res; } template<class InputIt, class Element> bool contains(InputIt first, InputIt last, const Element& elem) { return find(first, last, elem) != last; } template<class InputIt, class Element> bool binary_contains(InputIt first, InputIt last, const Element& elem) { return binary_search(first, last, elem) != last; } // TODO repace in c++17 with fold expressions template < class ... Ts > inline bool andAll ( Ts ... ); template < > inline bool andAll ( ) { return true; } template < class T, class ... Ts > inline bool andAll ( T value, Ts ... other ) { return value && andAll ( other ... ); } // TODO repace in c++17 with fold expressions template < class ... Ts > inline bool orAll ( Ts ... ); template < > inline bool orAll ( ) { return false; } template < class T, class ... Ts > inline bool orAll ( T value, Ts ... other ) { return value || orAll ( other ... ); } } /* namespace ext */ #endif /* __ALGORITHM_HPP_ */