我是 tmux 的新手,并将一个窗口分成 3 个窗格,左半部分(主窗格)、右上四分之一和右下四分之一。我是否可以使用命令在左侧主窗格中打开一个可编辑文件,例如vim myFile.py,并且 myFile.py 将在另一个窗格中打开,例如右上窗格,这样我就可以始终在右上窗格中编辑文件,并且将输入命令保留在左侧主窗格中吗?
看下面的例子,我使用了一个唯一的指针和一个原始指针a,我的问题是,为什么原始指针工作但不是唯一的指针?如果我想a通过使用unique_ptr或修改字符串作为引用shared_ptr,我该怎么办?
示例程序:
#include <iostream>
#include <string>
#include <memory>
int main()
{
using namespace std;
string a = "aaa";
auto ptr = std::make_unique<string>(a);
auto ptr2 = &a;
cout << "before, a: " << a << endl;
*ptr += "bbb";
cout << "After, a: " << a << endl;
*ptr2 += "ccc";
cout << "after 2, a: " << a << endl;
}
Run Code Online (Sandbox Code Playgroud)
输出:
before, a: aaa
After, a: aaa
after 2, a: aaaccc
Run Code Online (Sandbox Code Playgroud) 我正在研究 Boost 库,发现它大量使用了特征概念,例如 iterator_traits、graph_traits。特质是什么意思?您能否给我一个简单而简洁的例子来告诉我们为什么需要特质。据我目前所知,“特征”似乎意味着它包含我们可能需要的所有类型,这样我们就不会在类型上出错。
以下是boost中的graph_traits模板:
template <typename Graph>
struct graph_traits {
typedef typename Graph::vertex_descriptor vertex_descriptor;
typedef typename Graph::edge_descriptor edge_descriptor;
typedef typename Graph::adjacency_iterator adjacency_iterator;
typedef typename Graph::out_edge_iterator out_edge_iterator;
typedef typename Graph::in_edge_iterator in_edge_iterator;
typedef typename Graph::vertex_iterator vertex_iterator;
typedef typename Graph::edge_iterator edge_iterator;
typedef typename Graph::directed_category directed_category;
typedef typename Graph::edge_parallel_category edge_parallel_category;
typedef typename Graph::traversal_category traversal_category;
typedef typename Graph::vertices_size_type vertices_size_type;
typedef typename Graph::edges_size_type edges_size_type;
typedef typename Graph::degree_size_type degree_size_type;
};
Run Code Online (Sandbox Code Playgroud) 我想在代码片段(单独的函数)中收集我的程序的运行时间,当前的策略是计算chrono::duration每个部分的执行时间()并将它们相加。但是我必须处理两种不同的情况(使用不同的输入调用函数两次),并且我使用静态变量timer来保持分开的持续时间。现在我想在第二种情况之前重置变量。我怎样才能做到这一点?当然我可以使用连续两个 system_clock::now() 的持续时间,但这似乎没有必要。我试过timer = 0或timer(0),不起作用。例子:
class myClass {
static std::chrono::milliseconds timer_A;
void foo();
void bar();
}
Run Code Online (Sandbox Code Playgroud)
在 cpp 文件中:
std::chrono::milliseconds timer_A(0);
foo() {
...
// get someDuration1;
timer_A += someDuration1;
....
}
bar() {
...
// get someDuration2;
timer_A += someDuration2;
...
cout << timer_A.count();
}
Run Code Online (Sandbox Code Playgroud)
有一次main()遗嘱foo()和bar()两次。IE,
int main() {
if(someCondition) {
foo();
bar();
}
if(otherCondition) {
// here I need reset timer_A to 0 s.t. …Run Code Online (Sandbox Code Playgroud)