At first, I didn't really know what half of the code was doing (rarely did I even get past C++98, let alone 14), so I had to do my reading before I comment.
The idea of having functions be as flexible as that is rather brilliant, and I can see myself adopting it :P.
The compiler did throw 2 errors though (about not able to figure out the return types for "auto" of the average and size functions). Using "-> decltype(returntype)" after each function's declaration fixed the problem.
I can't understand what exactly did you do there for the new size() function.
(I find that hack to be kind of neat btw)
The idea of having functions be as flexible as that is rather brilliant, and I can see myself adopting it :P.
The compiler did throw 2 errors though (about not able to figure out the return types for "auto" of the average and size functions). Using "-> decltype(returntype)" after each function's declaration fixed the problem.
CPP-Code:
template <typename Cont> //requires std::Container<Cont> inline auto size(const Cont &cont) -> decltype(cont.size()) { return cont.size(); } template <typename Cont> //requires std::Container<Cont> auto average(const Cont &cont) -> decltype(*begin(cont)) { auto Sum = decltype(*begin(cont))(0);//deduce the return type, ugly hack, ISO committee please... for(auto &e:cont) Sum += e; return Sum/size(cont); } |
I can't understand what exactly did you do there for the new size() function.
(I find that hack to be kind of neat btw)
![[Image: signature.png]](http://s3.postimg.org/wedqxlk3n/signature.png)
A-Engine: A new beat em up game engine inspired by LF2. Coming soon
A-Engine Dev Blog - Update #8: Timeout