Re: [eigen] Best practices for accessing named regions within a larger array?

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


I see, here is a suggestion with a single get function templates by a
type encoding the required information and a little macro to the
definition of the names and their order:

  struct NIL { enum { ncols = 0, offset = 0 }; };

  #define ADD_ENTRY(NAME,NCOLS,PREV) \
  struct NAME { enum { ncols = NCOLS, offset = PREV::ncols + PREV::offset }; };

  ADD_ENTRY(rho,  1, NIL);
  ADD_ENTRY(rhou, 3, rho);
  // etc.

  template<tyepname T>
  storage_type::NColsBlockXpr<T::ncols>::Type get()
  { return storage.middleCols<T::ncols>(T::offset); }


  obj.get<rho>();

On Sun, Dec 4, 2011 at 11:49 PM, Rhys Ulerich <rhys.ulerich@xxxxxxxxx> wrote:
>> I'm not sure to understand your issue. Do you have a concrete example
>> of the "error-prone boilerplate" you are talking about?
>
> Sure.  A trimmed down version that compiles is attached.
>
> In practice I've got maybe four times the number of named regions.
> The example::ncols, example::offset, and accessor methods (spelled out
> here) can be generated using a single Boost.Preprocessor sequence and
> some auxiliary macros.  That cure is about as bad as the disease,
> however.  Tag-types and some Boost.MPL could accomplish the same but
> would also be ugly looking.
>
> - Rhys



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