Re: [eigen] Best practices for accessing named regions within a larger array? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Best practices for accessing named regions within a larger array?
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Mon, 5 Dec 2011 09:33:55 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=AnZS4y8uOh2XlNWGN7w6dF76RShBlbo+8gXxx0gfll8=; b=hpMtrEt6MbVKL5oAJEO8SHCADrthrTjNWPsE47unI1zE1Ab/s/TF50Yv0q1X4DhagM KYpfGEdWyqHbiqDulX+qqm39dop5DWAXVO+MP3Kvwqb+8mXRF9KYcYmvN8/scWScXzNF dp+Nq1WlEDCd8F2UjLwVMqbYFC4KiuoucXa60=
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