Algebraic structure in C++