Boost logo

Boost :

From: Doug Gregor (gregod_at_[hidden])
Date: 2001-01-13 20:45:46


On Friday 12 January 2001 07:00, you wrote:
> Paris (U.E;), le 13/01/2001
>
> I would absolutely welcome algebraic classes!

These are algebraic concept classes, not general algebraic classes. The idea
behind them is that they can be used to determine algebraic properties of a
given type. For instance, given the following integer exponentiation
algorithm (borrowed from some class notes at
http://www.cs.rpi.edu/~schupp/entries/COURSES/pl/notes/gp.html):

template<class SemigroupElement, class Integer>
SemigroupElement
exponentiate2(SemigroupElement x, Integer n) {
 while (even(n)) {
    x = x * x;
    n = n/2;
  }
  SemigroupElement P=x;
  n = integral_part(n/2);
  while (n>0) {
   x=x*x;
   if (odd(n))
      P = P*x;
   n = integral_part(n/2);
  }
  return P;
}

We should be checking that the type bound to SemigroupElement does indeed
form a semigroup with the operation *. The algebraic concept classes allow us
to do this check statically, so compilation will fail if the user does not
assert the associativity of * for the type bound to SemigroupElement.

        Doug Gregor
        gregod_at_[hidden]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk