Created
April 13, 2012 15:26
-
-
Save eiennohito/2377677 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct IteratorIterator { | |
template<class T, typename Func> | |
auto average(Func foo, T collection) -> decltype(foo(*collection.begin())) { | |
decltype(foo(*collection.begin())) accum = 0; | |
int size = 0; | |
for (typename T::const_iterator i = collection.begin(); i != collection.end(); ++i, size++) { | |
typename T::const_reference ref = *i; | |
accum += foo(ref); | |
} | |
return accum / size; // (size * 1.0)? Не выстрелить бы в ногу при приведении типов | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment