I have a function which I'd like to take a generic 2D array of some sort (T**, multi_array, or anything else that can be accessed in a 2D manner). I need to pull out the underlying element type.

It seems to me that a traits class is the right way to go, and that one probably exists which will work fine, but I don't know enough about traits classes to be sure.

For instance, I was considering iterator_traits<iterator_traits<Arr2DType>::value_type>::value_type, but the problem is that while this should work for a T** directly, I'd need to call begin() on a multi_array to get the appropriate iterator. So I thought about boost::begin(), but that doesn't say what it does on simple pointers, only fixed-size arrays.

Any suggestions?

Another option I was considering aside from traits classes was decltype(data[0][0]). Since this could be a reference type, I thought perhaps boost::remove_const<boost::remove_reference<decltype<data[0][0]>>>::type. Haven't tested that though. (And I may want to generalize element lookup so that I can support types which use a 2-element operator() as well.)