Sunday, May 3, 2015

LLVM/Clang Compatibility

The source code in the book relies on some Microsoft extensions to C++.  I have changed the online sample code to compile cleanly with LLVM.  There are two common cases where the resulting code is made significantly more awkward.

First, Microsoft allows derived classes to access public data members of their "dependent base class" (here "dependent" seems to mean "having a template parameter") directly; LLVM requires the use of the qualified name.

Second, consider the idiom for rescaling a matrix (here, shown for just one row and column):
auto doScale = bind2nd(multiplies<double>(), scale));
Transform(&corr->Row(ii), doScale);
Transform(&corr->Col(ii), doScale);
Microsoft allows this; but LLVM will not pass a pointer to the unnamed return values of Row and Col, and requires them to be assigned to named variables.

Thus the online code has become slightly more verbose and obscure.  The code in the book, where space is at a premium, continues to rely on Microsoft extensions.