Repository: opencv/opencv
File: modules/dnn/src/layers/centercroppad_layer.cpp (C++)

Code before:
        std::vector<int> axes;
        if (!axesTensor.empty())
        {
            CV_Assert(axesTensor.dims == 1);
            int naxes = (int)axesTensor.total();
            axes.resize(naxes);
            if (axesTensor.type() == CV_32S)
            {
                const int32_t* a32 = (const int32_t*)axesTensor.data;
                for (int i = 0; i < naxes; ++i) axes[i] = normalize_axis((int)a32[i], rank);
            }
            else
            {
                const int64_t* a64 = (const int64_t*)axesTensor.data;
                for (int i = 0; i < naxes; ++i) axes[i] = normalize_axis((int)a64[i], rank);
            }
        }
        else if (!axes_attr.empty())
        {
            axes.resize((int)axes_attr.size());
            for (size_t i = 0; i < axes_attr.size(); ++i) axes[i] = normalize_axis(axes_attr[i], rank);
        }
        else
        {
            axes.resize(rank);
            for (int i = 0; i < rank; ++i) axes[i] = i;
        }

        CV_Assert((int)shapeTensor.total() == (int)axes.size());

        if (shapeTensor.type() == CV_32S)
        {
            const int32_t* shp = (const int32_t*)shapeTensor.data;
            applyShapeFromPtr(shp, (int)axes.size(), axes, targetShape, usedAxes);
        }
        else if (shapeTensor.type() == CV_64S)
        {
            const int64_t* shp = (const int64_t*)shapeTensor.data;
            applyShapeFromPtr(shp, (int)axes.size(), axes, targetShape, usedAxes);
        }
    }

    bool getMemoryShapes(const std::vector<MatShape>& inputs,
                         const int /*requiredOutputs*/,
                         std::vector<MatShape> &outputs,
                         std::vector<MatShape> &internals) const CV_OVERRIDE
    {
        CV_Assert(inputs.size() >= 2);

        const MatShape& inShape = inputs[0];
        Net::Impl* netimpl_ = getNetImpl(this);

Review comment (suggestion):
You can use `std::iota` here: https://en.cppreference.com/w/cpp/algorithm/iota.html

Code after:
        std::vector<int> axes;
        if (!axesTensor.empty())
        {
            CV_Assert(axesTensor.dims == 1);
            int naxes = (int)axesTensor.total();
            axes.resize(naxes);
            if (axesTensor.type() == CV_32S)
            {
                const int32_t* a32 = (const int32_t*)axesTensor.data;
                for (int i = 0; i < naxes; ++i) axes[i] = normalize_axis((int)a32[i], rank);
            }
            else
            {
                const int64_t* a64 = (const int64_t*)axesTensor.data;
                for (int i = 0; i < naxes; ++i) axes[i] = normalize_axis((int)a64[i], rank);
            }
        }
        else if (!axes_attr.empty())
        {
            axes.resize((int)axes_attr.size());
            for (size_t i = 0; i < axes_attr.size(); ++i) axes[i] = normalize_axis(axes_attr[i], rank);
        }
        else
        {
            axes.resize(rank);
            std::iota(axes.begin(), axes.end(), 0);
        }

        CV_Assert((int)shapeTensor.total() == (int)axes.size());

        if (shapeTensor.type() == CV_32S)
        {
            const int32_t* shp = (const int32_t*)shapeTensor.data;
            applyShapeFromPtr(shp, (int)axes.size(), axes, targetShape, usedAxes);
        }
        else if (shapeTensor.type() == CV_64S)
        {
            const int64_t* shp = (const int64_t*)shapeTensor.data;
            applyShapeFromPtr(shp, (int)axes.size(), axes, targetShape, usedAxes);
        }
    }

    bool getMemoryShapes(const std::vector<MatShape>& inputs,
                         const int /*requiredOutputs*/,
                         std::vector<MatShape> &outputs,
                         std::vector<MatShape> &internals) const CV_OVERRIDE
    {
        CV_Assert(inputs.size() >= 2);

        const MatShape& inShape = inputs[0];
        Net::Impl* netimpl_ = getNetImpl(this);