c++11专题提供c++11的最新资讯内容,帮你更好的了解c++11。
我在 cppreference上读到关于如何推导出C 11 lambda的返回类型: if the body consists of the single return statement, the return type is the type of the returned expression (after rvalue-to-lvalue, array-to-pointer, or fun
在c 11中,如果我使用基于向量循环的范围,将保证迭代顺序? 说,以下代码块是否保证相同的输出? vector<T> output; vector<U> V; for( auto v: V) output.push_back(f(v)); VS for(int i =0; i < V.size(); ++i) output.push_back(f(V[i])); 如果不是矢量但地图等等呢? 是的,
我试图找到问题 C++ template non-type parameter type deduction的问题的解决方案,它不涉及调用f的模板参数,但隐含地为模板参数选择正确的类型. 由于constexpr应该保证一个函数只包含编译时常数,并且在编译时进行评估(至少我认为它是这样),我以为可能是这个问题的解决方案. 所以我想出了这个: template <class T, T VALUE> v
我最近在网上找到了这个漂亮的片段 – 它允许你绑定而不必传递明确的占位符: template <typename ReturnType, typename... Args> std::function<ReturnType(Args...)> easy_bind(ReturnType(*MemPtr)(Args...)) { return [=]( Args... args ) -> Ret
图书馆代码: class Resource { public: typedef void (*func_sig)(int, char, double, void*); //Registration registerCallback(void* app_obj, func_sig func) { _app_obj = app_obj; _fu
特定 std::list<std::vector<float>> foo; std::vector<float> bar; 如何在不复制数据的情况下将条形图移动到foo的末尾? 这个可以吗? foo.emplace_back(std::move(bar)); Is this ok? foo.emplace_back(std::move(bar)); 是的,因为: > std :: move(bar
考虑下面的代码g和clang(正确地)抱怨(构造函数A(int))在类D中是私有的.注意,由于A是D的虚拟基类,必须在D类的mem初始化器中初始化A,最多派生类,根据C.12中的§12.6.2/ 7.见 live example. class A { public: A(int i) : x(i) { } A() : x(1) {} int x; }; class B :
我正在学习如何编写基于循环的范围,但唯一的问题是我的编译器Orwell Dev-C似乎不支持它的默认模式(这是c 98).如何将此模式更改为支持此功能的其他功能(以及C 0x的其他功能).谢谢.也: 这是错误消息:[错误]在C 98模式下不允许基于范围的循环 我运行Windows 8 我有Dev C的版本是5.3.0.3 编译器是TDM-GCC 4.6.1 64位. 谢谢大家 转到工具 – >编译
使用线程我知道当线程变量离开作用域时会调用terminate(): size_t fibrec(size_t n) { return n<2 ? 1 : fibrec(n-2)+fibrec(n-1); } int main() { std::thread th{ fibrec, 35 }; // no join here } // ~th will call termina
如何执行std :: has_virtual_destructor和类似的检查?我试过在Visual Studio中看到type_traits头,但是有太多的宏和模板甚至可以得到一个想法.这个检查可以用任何相当简单的形式表达?我至少要知道它的工作原理,因为现在我不知道. 许多类型特征需要编译器魔术:traits实质上为不同编译器提供的一些钩子提供了一个库接口.编译器如何实现这些钩子完全取决于它们,
我有一个功能 int f(std::shared_ptr<MyClass> sptr); 之后我编写以下模板以便能够调用它(和其他一些)函数: template <typename Func, typename ArgType> auto call(Func func, ArgType arg) -> decltype(func(arg)) { return func(arg); } 当我
constexpr int get () { return 5; } template<int N> struct Test {}; int main () { int a[get()]; // ok Test< get() > obj; // error:'int get()' cannot appear in a constant-expression } 我有compiled
参见英文答案 > Is std::unique_ptr<T> required to know the full definition of T?                                    7个 我正在学习STFT课程.在标题中编译就好了: class STFT; // pimpl off to prevent point name clash class Whate
我对C 11很陌生,现在正试图通过避免直接使用指针来提高我的C技能.我正在尝试编写一个精灵管理器,它跟踪以前加载的精灵并释放未使用的精灵.我正在尝试使用shared_ptr(指向位图的指针),但是管理器还必须保持shared_ptr来创建精灵 – 所以引用计数不会下降到0.我可以以某种方式声明“父”shared_ptr在我的经理非拥有所以它不算作参考(并仍然创建该shared_ptr的拥有副本)?
我试图在dlopen()/ dlsym()周围编写一个C 0x包装来动态地从共享对象加载函数: class DynamicLoader { public: DynamicLoader(std::string const& filename); template<class Signature> std::function<Signature> load(std::
似乎make忽略了我的cflag选项,因为编译器抱怨我需要将-std = c 11作为标志,但该选项包含在我的makefile中. CC=g++ # Flags for the C compiler CXX_FLAGS= \ -Wall \ -std=c++11 \ -O2 # Linker Flags LD_FLAGS= # Sources to compile SO
假设我有以下代码: class B { /* */ }; class A { vector<B*> vb; public: void add(B* b) { vb.push_back(b); } }; int main() { A a; B* b(new B()); a.add(b); } 假设在这种情况下,所有原始指针B *可以通过unique_p
我最近读了很酷的文章: https://akrzemi1.wordpress.com/2015/08/20/can-you-see-the-bug/ 在ideone上使用简化版本我得到了令人惊讶的行为: #include <iostream> #include <cassert> using namespace std; int main() { const size_t sz=258;
如果我将shared_ptr’a’移动到shared_ptr’b’是’a’保证为null? 任何标准类的状态是否被移动指定? 一般17.6.5.15/1适用: Objects of types defined in the C++ standard library may be moved from (12.8). Move operations may be explicitly specifi
根据 these准则: If the default destructor is needed, but its generation has been suppressed (e.g., by defining a move constructor), use =default. 我无法想象,如果没有明确的默认析构函数在类中具有移动构造函数的代码将不正确. 有人可以告诉我上面的例子吗? stru