为什么std::make_unique标准C++ 11库中没有函数模板?我发现
std::unique_ptr<SomeUserDefinedType> p(new SomeUserDefinedType(1, 2, 3));
Run Code Online (Sandbox Code Playgroud)
有点冗长.以下不是更好吗?
auto p = std::make_unique<SomeUserDefinedType>(1, 2, 3);
Run Code Online (Sandbox Code Playgroud)
这隐藏得new很好,只提到一次类型.
无论如何,这是我尝试实现make_unique:
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
Run Code Online (Sandbox Code Playgroud)
我花了很std::forward长时间来编译这些东西,但我不确定它是否正确.是吗?究竟是什么std::forward<Args>(args)...意思?编译器对此做了什么?
在OSX C++程序编译期间g++我使用
LD_FLAGS= -Wl,-stack_size,0x100000000
Run Code Online (Sandbox Code Playgroud)
但在SUSE Linux中,我经常遇到如下错误:
x86_64-suse-linux/bin/ld: unrecognized option '--stack'
Run Code Online (Sandbox Code Playgroud)
和类似的.
我知道可以使用
ulimit -s unlimited
Run Code Online (Sandbox Code Playgroud)
但这并不好,因为单个用户并不总能做到这一点.
如何在单个应用程序中使用GCC增加Linux中的堆栈大小?