dimanche 17 mai 2020

How can I use decltype to get a pointer without a reference?

I have a function:

auto get_values_at_indices(auto* array, Vector<int>* indices)
{
    std::vector<decltype(*array)> ret(indices->size());

    for (int i = 0; i < indices->size(); i ++)
    {
        int index = indices[i];
        ret.push_back(array[index]);
    }

    return ret;
}

I'm calling the function with

MyClass** array = new MyClass[100];
std::vector<MyClass*> subset = get_values_at_indices(array, indices);

But the compiler sees decltype(*array) as MyClass*& (as opposed to MyClass*, which is what I want) - what should I try?

(PS, I tried std::vector<decltype(&(***array))> ret(indices->size()); but no dice ;)

Aucun commentaire:

Enregistrer un commentaire