I know arrays of references are not allowed, but have a couple of questions:
1) Why aren't arrays of references allowed :-) ?
2) What's a good practical alternative?
As an example, Intel's PXA255 processor's DMA controller has 16 consecutive
registers for DMA channel control & status called DCSRx. It would be nice to
have a short-hand access to these registers in addition to indirect access
through structure members:
// Simple hardware model
//
struct DMAController
{
Register DCSR[16];
Register DINT;
:
} dmac;
// Short-hand aliases
//
Register& DCSR0 = dmac.DCSR[0];
Register& DCSR1 = dmac.DCSR[1];
Register& DCSR2 = dmac.DCSR[2];
Register& DCSR3 = dmac.DCSR[3];
:
// This would be handy, but isn't allowed... and how would the references be
initialised in any case?
//
Register& DCSR[16];
If arrays of references were allowed, registers could be accessed using
DCSR[n]. Does anyone have a solution that would allow such convenient
short-hand? This is largely academic, since access through a structure
members will get the job done; however, I would be interested in any
thoughts and/or solutions (it bugs me). In general, if there is an array of
objects, how can access be provided to those objects by reference still
using array operators?
Tim