We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
容器的insert_range函数的行为,以deque_insert_range为例:
#include <stdio.h> #include <cstl/cdeque.h> int main(int argc, char* argv[]) { deque_t* pdeq = create_deque(int); iterator_t it; int i = 0; if (pdeq == NULL) { return -1; } deque_init(pdeq); deque_push_front(pdeq, 5); deque_push_front(pdeq, 4); deque_push_front(pdeq, 3); deque_push_front(pdeq, 2); deque_push_front(pdeq, 1); deque_push_front(pdeq, 0); deque_push_back(pdeq, 6); deque_push_back(pdeq, 7); deque_push_back(pdeq, 8); deque_push_back(pdeq, 9); for (it = deque_begin(pdeq); !iterator_equal(it, deque_end(pdeq)); it = iterator_next(it)) { printf("%d ", *(int*)iterator_get_pointer(it)); } printf("\n"); deque_insert_range(pdeq, iterator_next_n(deque_begin(pdeq), 4), deque_begin(pdeq), iterator_next_n(deque_begin(pdeq), 2)); for (it = deque_begin(pdeq); !iterator_equal(it, deque_end(pdeq)); it = iterator_next(it)) { printf("%d ", *(int*)iterator_get_pointer(it)); } printf("\n"); return 0; }
它的输出结果是:
0 1 2 3 4 5 6 7 8 9 0 1 2 3 2 3 4 5 6 7 8 9
而不是想象中的:
0 1 2 3 4 5 6 7 8 9 0 1 2 3 0 1 4 5 6 7 8 9
其实STL响应的代码也是这样的结果:
#include <iostream> #include <deque> int main(int argc, char* argv[]) { std::deque<int> deq; deq.push_front(5); deq.push_front(4); deq.push_front(3); deq.push_front(2); deq.push_front(1); deq.push_front(0); deq.push_back(6); deq.push_back(7); deq.push_back(8); deq.push_back(9); for (std::deque<int>::iterator it = deq.begin(); it != deq.end(); ++it) { std::cout << *it << " "; } std::cout << std::endl; deq.insert(deq.begin() + 4, deq.begin(), deq.begin() + 2); for (std::deque<int>::iterator it = deq.begin(); it != deq.end(); ++it) { std::cout << *it << " "; } std::cout << std::endl; return 0; }
输出结果:
像这样的行为需要记录到教程或者参考手册中。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
容器的insert_range函数的行为,以deque_insert_range为例:
它的输出结果是:
而不是想象中的:
其实STL响应的代码也是这样的结果:
输出结果:
像这样的行为需要记录到教程或者参考手册中。
The text was updated successfully, but these errors were encountered: