Re: [eigen] proposal to use static const integer class members instead of enum values

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


On Sat, 13 Dec 2014, Benoit Jacob wrote:

Anyway, my proposal seems pretty much dead at this point. Eigen's constants
have been public and passable by const reference for years, so surely
people are depending on it now, and we shouldn't break them. As to the idea
of inheriting from an integral_constant struct, as far as I can see, Eigen
doesn't have anywhere to put the definition of such structs, since it is
headers-only, contrary to libc++ / libstdc++.

template<class>struct A{
  static const int i = 42;
};
template<class T> const int A<T>::i; // (1)
void f(const int&){}
int main(){
  f(A<char>::i);
}

This works even if line (1) is in a header, as multiple such definitions will be merged (like inline functions). But it only works for templates. And it is a pain to add a definition for each (public) constant.

The main goal of deriving from integer_constant is to have only one class that needs the definition, as long as the constant is always called value. But since in Eigen the constants can have many, many different names (IsColVector, ExpandMem, RowsAtCompileTime, OuterSize, etc) it wouldn't gain much if anything.

--
Marc Glisse



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/