Boost logo

Boost :

From: Eric Woodruff (Eric.Woodruff_at_[hidden])
Date: 2002-09-26 10:00:06

I can't remember, does C++ allow int const[100][100] or even int const[100]
const[100] const (wacky stuff...)? Or does one have to make it: int const*
const* const stat = { ... }? It's been a very long time since I used an

This is assuming one would want it constant since it is a compile-time
filled array. It is a shame that boost::array is only one-dimensional.

----- Original Message -----
From: Douglas Gregor
Newsgroups: gmane.comp.lib.boost.devel
Sent: Thursday, 2002:September:26 10:42
Subject: Re: compile time array initialization

On Thursday 26 September 2002 03:23 am, Gennadiy Rozental wrote:
> Let say I have one global array int stat[100][100]. And want to write an
> initializer for it that follow formula like this:
> if j2 > j >= j1 && i2 > i >= i1
> x[i][j] = i - i1;
> else
> x[i][j] = 0
> Or something similar.
> Obviously I could type all the elements, but it's inconvenient, difficult
> to change and error prone. Could MPL or BOOST_PP be of some help here?

The preprocessor library can do this. The result would look something like
this, but beware the untested code:

#define STAT_ELEMENT(J,I) \
    I - I1, \


int stat[100][100] = {

I didn't have any idea where I1, I2, J1, and J2 came from, so they are just
assumed to be macros. However, you could package them in a tuple if they
to be passed in.


Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at