Boost logo

Boost Users :

Subject: [Boost-users] [multi_array] How to specify degenerate at runtime?
From: Anton Daneyko (self_at_[hidden])
Date: 2011-12-12 18:24:08


Greetings to Boosters,

I have a 3D multi_array and I would like to make 2D slices using dimensions
specified at runtime. I know the index of degenerate dimension and an index
of slice, that I want to extract in that degenerate dimension. Currently
the ugly workaround looks like that:
    if (0 == degenerate_dimension)
    {
        Slice slice =
input_array[boost::indices[slice_index][range()][range()]];
    }
    else if (1 == degenerate_dimension)
    {
        Slice slice =
input_array[boost::indices[range()][slice_index][range()]];
    }
    else if (2 == degenerate_dimension)
    {
        Slice slice =
input_array[boost::indices[range()][range()][slice_index]];
    }

Is there a more beautiful way to construct index_gen object?
Something like that:
    var slicer;
    for(int i = 0; i < 3; ++i) {
        if (degenerate_dimension == i)
            slicer = boost::indices[slice_index];
        else
            slicer = boost::indices[range()];
    }
    Slice slice = input_array[slicer];

It seems each subsequent call to boost::indices::operator[] returns a
different type depending on the dimensionality, so there's no way to use a
single variable, that can hold the temporary index_gen object.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net