- Invalid signature
void main()
(… I mean, seriously?!) - Missing namespace qualifiers throughout
- Missing include for
accumulate
- Missing
)
inaccumulate
call - Invalid arguments to
accumulate
call:init
missingop
has wrong function type (expected(T, T) -> T
; got(T) -> void
)- — in fact, it seems they actually meant
std::for_each
.
- … but using
std::accumulate
correctly would have been way easier, without a gratuitous lambda. - Expensive copy of
base_quals()
(this should absolutely be captured by const-ref) - Inconsistent indentation
- Misleading variable naming:
abq
is a sum, not an average, of base qualities. - Unused, gratuitous constant declaration
- Expensive
endl
instead of'\n'
Here’s a cleaned up version:
#include "gamgee/gamgee.h"
#include <iostream>
#include <numeric>
int main() {
for (auto const& record : gamgee::SingleSamReader("input.bam")) {
auto const& bqs = record.base_quals();
auto const sum_qual = std::accumulate(bqs.begin(), bqs.end(), 0.0);
std::cout << sum_qual / bqs.size() << "\n";
}
}