#pragma once #include namespace bts { namespace sane { template T max(const TCollection& collection, TGet get) { auto max = std::numeric_limits::min(); for (const auto& item : collection) { if (max < get(item)) { max = get(item); } } return max; } template T min(const TCollection& collection, TGet get) { auto min = std::numeric_limits::max(); for (const auto& item : collection) { if (min > get(item)) { min = get(item); } } return min; } // Calculate min using transform on T (i.e. a member accessor) template const T* min_by(const TCollection& collection, TGet get) { auto min = std::numeric_limits::max(); const T* pitem = nullptr; for (const auto& item : collection) { if (min > get(item)) { min = get(item); pitem = &item; } } return pitem; } template bool true_for_all(const TCollection& collection, TWhat what) { for (const auto& item : collection) { if (!what(item)) return false; } return true; } template void map(const TSrc& source, TDest& dest, const TFn& fn) { std::transform(std::begin(source), std::end(source), std::inserter(dest, dest.end()), fn); } }}//namespace