I'm trying to sort a 2D, dynamically allocated array using std::sort
with a custom sorting function using lambda. numFaces
is an integer value determined at the start of the program and doesn't change during the program's lifespan. Here's my current approach.
float(*data)[24] = new float[numFaces][24];
std::sort(data, data + numFaces, [](float (&A)[24], float (&B)[24]) -> bool
{
return comparison(A, B); // Pseudo
});
The program is failing to compile with this error:
array type 'float [24]' is not assignable
Since I've specified in the lambda declaration that the parameters should be references I can't see why the compiler is producing this error message. I am using the VC++ compiler from Microsoft's Visual Studio Community Edition 2015. Here's a quick pastebin of the entire log
Line 38 is the closing bracket of the lambda function declaration.
I know I could solve this in a couple different ways, but if there is a way to make this work, I would prefer to continue like this. If you have a suggestion to another solution that lets the data be stored contiguously and sorted in these groups of 28 floats I would be delighted to hear about that too.
Ways I could solve the current issue which would introduce other issues and/or bigger delay in the application:
- Using
qsort
with void pointers, casting them and sorting pretty much the same way. I'm a bit unsure whether or not this would introduce any more delay when thestd::sort
doesn't have all the information about the container that it would have if I was usingstd::vector
s. - Using
std::sort
with nestedstd::vector
s. The data wouldn't always be stored contiguously on memory, which would in turn force me to create copies of the data every time the vector is sorted. I tested this and checked the locations on memory with the VS debugger, but again I am not 100% sure this can't be solved somehow. - Using
std::vector
of a custom class/struct with the needed data. If there is no simple solution to my problem I will do this or do the sorting without any STL calls.
Tiny notice: The code in the code tag above has been stripped of unnecessary code. The pastebin is a bit different because of this.
Aucun commentaire:
Enregistrer un commentaire