如何使用libgit2遍历分支的所有提交?
我已经有了下面的代码,但它没有编译.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <git2.h>
int main(int argc, char *argv[]){
git_repository *repo;
git_repository_open(&repo, ".");
git_odb *obj_db;
obj_db = git_repository_database(repo);
git_object commit;
git_revparse_single(&commit, repo, "HEAD");
git_repository_free(repo);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
GCC报告:
log.c: In function ‘main’:
log.c:11:9: warning: assignment makes pointer from integer without a cast [enabled by default]
log.c:13:13: error: storage size of ‘commit’ isn’t known
Run Code Online (Sandbox Code Playgroud)
我用-lgit2
旗子编译.从root-commit开始,是否有可能快速完成所有提交?
更新 新代码如下所示:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <git2.h>
int main(int argc, char *argv[]){
git_repository *repo;
git_repository_open(&repo, …
Run Code Online (Sandbox Code Playgroud) 像这样定义我的priority_queue,
priority_queue<int> parts(start, start+N, less<int>());
Run Code Online (Sandbox Code Playgroud)
以下代码将无法编译
for(int t : parts){
...
}
Run Code Online (Sandbox Code Playgroud)
这引出了我的问题:
在C++ 11中,是否允许基于范围的循环 std::priority_queue
?
通常,允许使用基于范围的for循环迭代哪些结构?
我知道我可以做同样的事情:
while(!parts.empty()){
cout << "Next element: " << parts.top() << endl;
parts.pop();
}
Run Code Online (Sandbox Code Playgroud)
是否可以通过队列进行迭代?