コメントは以下の通りです。私はstd::priority_queue<std::unique_ptr<...>>
のトップを見る必要がありますが、私が.top()
を呼び出すと、「削除された関数を参照しようとしています」というコンパイラエラーが発生します。私はポップと呼ぶことができることを知っていますが、私はそれをポップするかどうかを決定するためにまず値に基づいていくつかのロジックを行う必要があります。ポップや所有権を持たずに、std :: priority_queue <std :: unique_ptr <...>>の先頭をどうやって調べるか
struct MyStruct {
int val = 2;
MyStruct(const int val) : val(val) {}
};
void testDeque() {
// This block won't compile because of call to q1.top()
std::priority_queue<std::unique_ptr<MyStruct>> q1;
q1.emplace(std::make_unique<MyStruct>(10));
// How can I "peek" at the value at q1.top() without taking ownership of the unique_ptr?
MyStruct* nonOwnershipPtr = DO_SOMETHING_MAGIC(q1.top());
// At this point, the unique_ptr at t1.top() should still be there
}
'はトップ()'あなたが参照できますし、あなたがやりたいようにする必要があります。おそらく 'DO_SOMETHING_MAGIC'にバグがあります。 –
@KerrekSB関数のバグであるとは限りません。そのパラメータを 'const&'で取るだけです。 –