- #include <iostream>
- #include <stdlib.h>
- #include <vector>
- #include <boost/pending/mutable_queue.hpp>
- using namespace boost;
- using namespace std;
- struct node {
- int id;
- int value;
- };
- struct compare_node: public std::binary_function<struct node*, struct node*, bool>{
- bool operator()(struct node *const& n1, struct node *const & n2) const {
- return (n1->value < n2->value);
- }
- };
- struct node_identity_property_map : public boost::put_get_helper<std::size_t, node_identity_property_map> {
- inline std::size_t operator[](struct node *const & v) const { return v->id; };
- };
- typedef mutable_queue<struct node *, vector<struct node*>,
- compare_node, node_identity_property_map> mutable_queue_t;
- #define SIZE_ID_SPACE 10
- int main() {
- mutable_queue_t q(SIZE_ID_SPACE, compare_node(), node_identity_property_map());
- struct node nodes[10];
- cout << "putting items......" << std::endl;
- for (int i = 0; i < SIZE_ID_SPACE; i++) {
- nodes[i].id = i;
- nodes[i].value = i;
- cout << "id=value=" << i << endl;
- q.push(&nodes[i]);
- }
- for (int i = 0; i < SIZE_ID_SPACE; i++) {
- nodes[i].value = rand();
- q.update(&nodes[i]);
- }
- cout << std::endl << "retrieving items......" << std::endl;
- for (int i = 0; i < SIZE_ID_SPACE; i++) {
- std::cout << "id: " << q.top()->id << "\t" << q.top()->value << std::endl;
- q.pop();
- }
- return 0;
- }
사고뭉치네 생각창고
2011년 3월 5일 토요일
Use of structure pointer with boost::mutable_queue
I have worked on this for a few hours and finally made the whole thing work. Few article explained about either comparators with pointers or use of structure with mutable_queue, and I decided to dig the source code of STL directly. The following code is the gist of what I got from the somewhat long search:
2010년 10월 22일 금요일
10/21 today's idiom
Emmett said..
"I'd give it one more day (or so) to circumvent futexes. Otherwise, I guess it is time to roll up the old sleeves..."
roll up your sleeves: to prepare for hard work
"I'd give it one more day (or so) to circumvent futexes. Otherwise, I guess it is time to roll up the old sleeves..."
roll up your sleeves: to prepare for hard work
After the election, the mayor rolled up his sleeves and began immediately to put his promises into action.
피드 구독하기:
덧글 (Atom)