我最近在我的vim配置中添加了NERDTree和NERDTreeTabs,我对此感到非常高兴.
但是,我想进一步配置它并具有以下行为:
Ctrl+ Left:
如果在NERDTree内,什么也不做.
如果在编辑的文件中,请转到打开的NERDTree,如果没有,则先打开一个NERDTree.我想NERDTreeTabsToggle应该使用,但要使用它,我必须能够检测NERDTree是否已经打开,而不是通过"切换"它来关闭它.
Ctrl+ Right:
如果在NERDTree内,请返回已编辑的文件而不关闭NERDTree.(就像什么Ctrl- w,Right会做什么.)
如果在编辑的文件中,隐藏/关闭NERDTree.
但是,我的Vim脚本技能对我来说是很低的,以获得任何令人满意的结果.例如,我无法弄清楚如何检查当前活动窗口是什么或如何编写适当的条件语句.
有人可以帮助我吗?
谢谢.
class Student{
public:
Student(int test)
:key(705)
{
if(test == key)
{cout << "A student is being verified with a correct key: "<< test << endl;
allow=1;
}
else
{
cout << "Wrong key" ;
}
}
friend void printResult();
private:
const int key;
int allow;
};
void printResult()
{
if(allow==1)
{
cout<< " Maths: 75 \n Science:80 \n English: 75" << endl;
}
}
int main()
{
int testkey;
cout << "Enter key for Bob: ";
cin >> testkey;
Student …Run Code Online (Sandbox Code Playgroud) 我必须C++围绕现有的C库创建一组包装类.
对于C库的许多对象,构造是通过调用类似britney_spears* create_britney_spears()和相反的函数来完成的void free_britney_spears(britney_spears* brit).
如果分配britney_spears失败,则create_britney_spears()返回NULL.
据我所知,这是一种非常常见的模式.
现在我想把它包装在一个C++类中.
//britney_spears.hpp
class BritneySpears
{
public:
BritneySpears();
private:
boost::shared_ptr<britney_spears> m_britney_spears;
};
Run Code Online (Sandbox Code Playgroud)
以下是实施:
// britney_spears.cpp
BritneySpears::BritneySpears() :
m_britney_spears(create_britney_spears(), free_britney_spears)
{
if (!m_britney_spears)
{
// Here I should throw something to abort the construction, but what ??!
}
}
Run Code Online (Sandbox Code Playgroud)
所以问题出在代码示例中:我应该抛弃什么来中止构造函数?
我知道我几乎可以扔任何东西,但我想知道通常做什么.我没有关于分配失败原因的其他信息.我应该创建自己的异常类吗?std这种情况有例外吗?
非常感谢.
在我的项目中,我最近决定使用boost :: thread.我的代码在Linux下编译得很好,但在Windows下(x86或x64),我在gcc 4.5中得到以下警告:
In file included from C:\Boost\include\boost-1_44/boost/thread/shared_mutex.hpp:14:0,
from C:\Boost\include\boost-1_44/boost/thread/detail/thread_group.hpp:9,
from C:\Boost\include\boost-1_44/boost/thread/thread.hpp:24,
from C:\Boost\include\boost-1_44/boost/thread.hpp:13,
from include\systools/upnp_control_point.hpp:50,
from src\upnp_control_point.cpp:45:
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp: In member function 'T boost::shared_mutex::interlocked_
compare_exchange(T*, T, T) [with T = boost::shared_mutex::state_data]':
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:110:103: instantiated from here
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:50:99: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:50:99: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:51:52: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:51:52: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
In file included from …Run Code Online (Sandbox Code Playgroud) 通常,当我必须显示一个单独的字符串列表时,我做了类似的事情:
using namespace std;
vector<string> mylist; // Lets consider it has 3 elements : apple, banana and orange.
for (vector<string>::iterator item = mylist.begin(); item != mylist.end(); ++item)
{
if (item == mylist.begin())
{
cout << *item;
} else
{
cout << ", " << *item;
}
}
Run Code Online (Sandbox Code Playgroud)
哪个输出:
apple, banana, orange
Run Code Online (Sandbox Code Playgroud)
我最近发现std::ostream_iterator如果发现它真的很好用.
但是使用以下代码:
copy(mylist.begin(), mylist.end(), ostream_iterator<string>(cout, ", "));
Run Code Online (Sandbox Code Playgroud)
如果得到:
apple, banana, orange,
Run Code Online (Sandbox Code Playgroud)
几乎完美,除了额外的,.是否有一种优雅的方式来处理特殊的"第一个(或最后一个)元素"并且具有与第一个代码相同的输出,而没有它的"复杂性"?
我正在使用boost::python创建C++库的Python包装器.在某些时候,boost::python需要一个指向成员函数(或兼容的东西)的指针,如:
template <class MyClass, typename ValueType>
void (*setter_function)(MyClass&, ValueType)
// This doesn't compile, but you got the idea.
my_boost_python_call(setter_function f);
Run Code Online (Sandbox Code Playgroud)
由于我正在包装的类具有以下形式的setter:
template <class MyClass, typename ValueType>
MyClass& (MyClass::*setter_method)(ValueType)
Run Code Online (Sandbox Code Playgroud)
我写了一个"转换"功能:
template <typename MyClass, typename ValueType, setter_method<MyClass, ValueType> fluent_setter>
void nonfluent_setter(MyClass& instance, ValueType value)
{
(instance.*fluent_setter)(value);
}
Run Code Online (Sandbox Code Playgroud)
我可以这样使用:
class Foo
{
public:
Foo& bar(int value);
};
my_boost_python_call(nonfluent_setter<Foo, int, &Foo::bar>);
Run Code Online (Sandbox Code Playgroud)
到目前为止,这种方法效果很好,但我想知道是否有办法让这更加"简单"(使用).
你觉得在某种程度上可能得到这样的东西:
// return type is somehow inferred from the member function pointer
my_boost_python_call(nonfluent_setter<Foo, &Foo::bar>);
// or even a …Run Code Online (Sandbox Code Playgroud) 我正在设计一个基本网站,其访问受到经典登录和密码系统的限制。
我无法决定当用户输入不存在的登录名以及输入现有帐户的无效密码时是否应该显示不同的消息。
我的第一直觉是不要显示不同的消息,因为这会给潜在的攻击者暗示哪里出了问题,但这样做有时会让用户更难以理解他的错误(也许他只是错误地输入了他的帐户登录信息和适当的信息)错误信息会更好)。另一方面,我经常听说帐户登录不是秘密(密码显然也是如此),因此提供有关帐户的信息不应降低安全级别。
你们有什么好的做法/理由我应该遵循吗?
谢谢。
我最近将sessionman插件添加到我的 Vim 配置中,到目前为止我很喜欢它。
\n我知道 Vimv:this_session在使用会话时设置为会话文件名,并且我\xe2\x80\x99d 喜欢将其添加到我的状态行。不幸的是,v:this_session包含完整的文件路径,并且它通常太长,无法容纳在状态行中。
所以我的问题是:如何提取没有完整路径的文件名v:this_session并将其添加到我的状态行?
我无法设法垂直对齐inline-block <span>元素内部的<td>元素(具有默认display: table-cell样式).
两个元素都有固定的大小:<td> is 24px tall and so is the`.
我希望这两个元素具有相同的渲染大小,因为它们都没有边距或填充.然而,它似乎<td>比预期更高,我无法弄清楚为什么.
这个jsfiddle的例子.
你知道为什么会发生这种情况以及如何"修复"它吗?
在Python 2.7中,我注意到repr(s)(s作为一个字符串)行为因s内容而异.
这就是我的意思:
In [1]: print repr("John's brother")
"John's brother"
In [2]: print repr("system")
'system'
Run Code Online (Sandbox Code Playgroud)
请注意两种情况下的不同引号类型.
从我的测试看来,只要s包含一个'字符,所引用的字符串就会被引用," 除非该字符串还包含一个(转义的)"字符.
这是我的意思的一个例子:
In [3]: print repr("foo")
'foo'
In [4]: print repr("foo'")
"foo'"
In [5]: print repr("foo'\"")
'foo\'"'
Run Code Online (Sandbox Code Playgroud)
现在我明白它没有任何区别,因为repr不提供有关确切输出格式的任何保证,但我很好奇为什么Python开发人员决定了这些东西:
doctests变得更难写.