Language: C++

#include <cassert>
#include <cstdint>
#include <functional>
#include <vector>

template <typename Abelian> class FenwickTree {
	using uint32 = std::uint_fast32_t;
	using const_reference = const Abelian &;
	using F = std::function<Abelian(const_reference, const_reference)>;
	const Abelian neutral_;
	const F p, m;
	std::vector<Abelian> tree;

public:
	FenwickTree(const uint32 size, const_reference neutral = Abelian(),
		const F &p = std::plus<Abelian>(),
		const F &m = std::minus<Abelian>())
		: neutral_(neutral), p(p), m(m), tree(size + 1, neutral_) {}
	FenwickTree(const uint32 size, const_reference neutral, const F &p,
		const std::function<Abelian(const_reference)> &n)
		: neutral_(neutral), p(p),
		m([](const_reference l, const_reference r) { return p(l, n(r)); }),
		tree(size + 1, neutral_) {}
	void update(uint32 index, const std::function<void(Abelian)> &g) {
		assert(index < tree.size() - 1);
		++index;
		const Abelian a = tree[index];
		g(tree[index]);
		const_reference b = tree[index];
		while ((index += index & ~index + 1) < tree.size())
			tree[index] = p(m(tree[index], a), b);
	}
	void update(uint32 index, const_reference data) {
		update(index, [&](Abelian &d) { d = data; });
	}
	void add(uint32 index, const_reference diff) {
		assert(index < tree.size() - 1);
		++index;
		do
			tree[index] = p(tree[index], diff);
		while ((index += index & ~index + 1) < tree.size());
	}
	Abelian range(uint32 end) const {
		assert(end < tree.size());
		Abelian ret = neutral_;
		do
			ret = p(tree[end], ret);
		while (end &= end - 1);
		return ret;
	}
	Abelian range(uint32 begin, uint32 end) const {
		assert(begin <= end);
		return m(range(end), range(begin));
	}
	Abelian operator[](uint32 index) const {
		assert(index < tree.size() - 1);
		return range(index, index + 1);
	}
};

#include <iostream>
int main(void) {
	int n, q;
	std::cin >> n >> q;
	FenwickTree<int> T(n, 0);
	while (q--) {
		int c, x, y;
		std::cin >> c >> x >> y;
		if (c) {
			std::cout << T.range(x - 1, y) << "\n";
		}
		else {
			T.add(x-1,y);
		}
	}
	return 0;
}


Compiler output:
a.cc: In lambda function:
a.cc:22:69: error: 'p' is not captured
   22 |                 m([](const_reference l, const_reference r) { return p(l, n(r)); }),
      |                                                                     ^
a.cc:22:20: note: the lambda has no capture-default
   22 |                 m([](const_reference l, const_reference r) { return p(l, n(r)); }),
      |                    ^
a.cc:19:74: note: 'const FenwickTree<Abelian>::F& p' declared here
   19 |         FenwickTree(const uint32 size, const_reference neutral, const F &p,
      |                                                                 ~~~~~~~~~^
a.cc:22:74: error: 'n' is not captured
   22 |                 m([](const_reference l, const_reference r) { return p(l, n(r)); }),
      |                                                                          ^
a.cc:22:20: note: the lambda has no capture-default
   22 |                 m([](const_reference l, const_reference r) { return p(l, n(r)); }),
      |                    ^
a.cc:20:64: note: 'const std::function<Abelian(const Abelian&)>& n' declared here
   20 |                 const std::function<Abelian(const_reference)> &n)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^