const-iterator

    0熱度

    1回答

    您是否還記得我之前的問題:What is causing data race in std::async here? 即使我成功並行化了這個程序,它仍然仍然跑得太慢而不切實際。 所以我試圖改進代表康威的生命遊戲模式的數據結構。 新結構的簡要說明: class pattern { // NDos::Lifecell represents a cell by x and y coordina

    3熱度

    1回答

    Why does boost::find_first take a non-const reference to its input?的評論建議「調用者創建一個帶const_iterator模板參數的非const iterator_range來」證明「迭代對象具有足夠的生命週期。 這是什麼意思,我該怎麼做? 特別是,如何使用此代碼實現const正確性? typedef std::map<int,

    1熱度

    1回答

    例如,我可以定義在某種程度上類似於一個容器: template <typename T> class Example { public: using value_type = T; using iterator = value_type*; using const_iterator = const iterator; //etc }; 然而,是不

    0熱度

    1回答

    我正面臨基於MultiIndex容器中迭代器的Projected值的排序問題。以下是完整的代碼。我在這裏刪除的是SellOrderRecord的調用,因爲調用的函數與GenerateData相同,但預期結果不同,與前10名最小記錄,而在BuyOrderRecord應導致前10名最大記錄。 我強制迭代到500,假設我會在該範圍內得到最大/最小值,這是錯誤的。我需要取的是十大獨特的價格,如果價格重複,

    4熱度

    1回答

    這是今天的第二個編譯器錯誤,讓我感到困惑。不知何故,下面的代碼,gcc抱怨代碼的函數返回一個迭代器return_iter返回衝突類型std::_Rb_tree_iterator<const int*>然後std::_Rb_tree_const_iterator<const int*>,但它們都不應該是const迭代器,因爲該集合不是const。任何人都可以解釋爲什麼在非const左值上調用std:

    2熱度

    2回答

    讓說我定義某種容器A的: struct A { iterator begin(){ return iterator(this,0); } const iterator cbegin() const { return iterator(this, last());} //... }; 假設現在我要宣佈iterator(A部分): struct A::iterat

    0熱度

    1回答

    我目前還不熟悉C++編程,我正在嘗試製作一個數獨求解器。 但是,我遇到了返回單元格候選列表的方法(單元格可能的值列表)的問題。 候選人列表是一個向量。這是我目前如何嘗試做到這一點,但它是來了一個錯誤: int Cell::getCandidateList(void) const { int i; for (vector<int>::iterator j = m_candidateList.b

    0熱度

    2回答

    我有點搞砸了const_iterators。例如,讓我們考慮的功能: void functionForConstIterator(std::list<int> const& list, std::list<int>::const_iterator& const_iter) { const_iter = list.begin(); } 現在我能寫: void main() {

    1熱度

    3回答

    我遍歷結構向量中的一組元素並想要更改其中一個結構中的元素。當我寫入元素來更改值時,更新不會保留。以下是我有: 首先,在頭文件: std::vector<Sched::ScheduledEvent_t> v_SchedEvents; typedef std::vector<Sched::ScheduledEvent_t>::const_iterator event_iter; 後來在一個.cp

    2熱度

    3回答

    有時候我會想用算法庫中函數返回的迭代器。我在修改函數和非修改函數之間出現問題。原因在非修改功能我想使用const_iterator。作爲玩具的例子: vector<int> v = { 1, 8, 7, 4, 3, 6, 2, 5 }; auto it = partition(begin(v), end(v), bind(greater<int>(), placeholders::_1, 3))