I'm getting a lot of use of deleted function error. I just changed the pointer of weighted_pointer
to unique_ptr
. But I can't realize why I'm getting the error, any tip?
The likeatree
is a DAG structure which can point to another struct or an element of stdDeque
based on mask value.
The weight
of weighted_pointer
has mutable
keyword because doesn't change where in the set will be.
#include <deque>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <memory>
#include <chrono>
using namespace std;
struct likeatree{
unsigned int mask : 3;
void * a;
void * b;
};
struct weighted_pointer{
mutable int weight;
unique_ptr<likeatree> ptr;
};
struct ptrcomp{
bool operator()(const weighted_pointer lhs, const weighted_pointer rhs) {
if(lhs.ptr->mask < rhs.ptr->mask)
return true;
if(lhs.ptr->mask > rhs.ptr->mask)
return false;
if(lhs.ptr -> a < rhs.ptr->a)
return true;
if(lhs.ptr->a > rhs.ptr->a)
return false;
return lhs.ptr->b < rhs.ptr->b;
}
};
vector<likeatree *> treeVector;
deque<bool> stdDeque(3);
vector<vector<bool>> boolMatrix{{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}};
set<weighted_pointer,ptrcomp> stdSet;
int main(){
srand(time(NULL));
weighted_pointer tmp;
tmp.weight = 1;
for(unsigned int i = 0; i < stdDeque.size(); i++){
tmp.ptr.reset(new likeatree{0,&stdDeque[i],nullptr});
stdSet.insert(tmp);
}
for(unsigned int i = 0; i < boolMatrix.size(); i++){
treeVector.push_back(tmp.ptr.get());
}
for(unsigned int i = 0; i < treeVector.size(); i++){
auto it = find_if(stdSet.begin(),stdSet.end(),[&](weighted_pointer temp){ return temp.ptr.get() == treeVector[i]; });
/* ... */
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire