c++11专题提供c++11的最新资讯内容,帮你更好的了解c++11。
Visual Studio 2015更新3改进了对C 11的支持,但我有一个奇怪的问题,我正在寻找解决方法. 当使用MSVC为模板类型参数(“完全定义的类型”)编译可变参数模板代码时,一切都很好,但是如果我想使用模板模板参数(“部分定义的类型”),则结果变得不正确. #include <iostream> using namespace std; template <template<typen
根据: constexpr static data member giving undefined reference error static constexpr类成员必须满足两个要求: template <typename Tp> struct wrapper { static constexpr Tp value{}; // 1 }; template<typename Tp> con
我正在尝试创建一个通用运算符<<对于std :: ostream和任何Iterable类型. 这是代码: template <class T,template<class> class Iterable> inline std::ostream& operator<<(std::ostream& s,const Iterable<T>& iter){ s << "[ "; bool
我已经成功编写了一个像这样的类,在一个被定义为所述类的非静态属性的lambda中捕获它: #include <memory> #include <iostream> #include <functional> struct S { S() { std::cout << "S::S()[" << this << "]" << std::endl; } std::strin
示例代码 #include <iostream> struct base {}; template<typename Type> struct left : base { Type value; }; template<typename Type> struct right : base { Type value; }; int main() { std::cout
我似乎无法在C 11中使用本地静态值作为模板参数.例如: #include <iostream> using namespace std; template <const char* Str> void print() { cout << Str << endl; } int main() { static constexpr char myStr[] = "Hello"; pri
参见英文答案 > Why is list initialization (using curly braces) better than the alternatives?                                    3个 在C 11中,可以使用统一初始化初始化结构,如下所示: struct BasicStruct { BasicStruct (int x, do
C 11引入了统一初始化,其具有禁止隐式缩小转换的期望特征.例如,int i {2.2}应该是一个错误. 不幸的是,出于向后兼容性的原因,C 03,GCC自4.7以来只给出了这些警告. GCC的documentation表明此扩展不适用于SFINAE环境,但似乎是错误的: #include <type_traits> #include <utility> template <typename F
我有一个(第三方)类是不可复制的.我想初始化它们的数组.这是我最好的尝试: #include <array> class Thing { public: explicit Thing(int) {} Thing(const Thing&) = delete; }; int main() { std::array<Thing, 1> things{{{100}}}; // error
使用std :: get<>()和std :: tie<>()以及boost构造有什么选择? 例: 我想使用基于范围的for循环来迭代几个容器.我可以实现zip函数,它使用boost :: zip_iterator. #include <boost/iterator/zip_iterator.hpp> #include <boost/range.hpp> template <typename
当我使用clang(版本3.4(主干194574))来编译它: typedef void (* FunctionThatNeverReturns [[ noreturn ]])(); 我明白了: error: 'noreturn' attribute only applies to functions and methods 这让我感到惊讶,因为它与旧版本的clang完美搭配. 那么如何定义指向[
以下代码是否合法(在c 11/14中)? bool foo() { union bar { int i; bool b; }; union baz { char c; bar b; }; auto b = baz{'x'}; auto barptr = &b.b; auto boolptr = &barptr->b; new (boolptr) bool{true};
至于我使用“转换构造函数”,它们看起来像这样: struct X { X(A); // conversion from A -> X X(B,C = someC); // conversion from B -> X, with some default C }; X x1 = A(); // calls X::X(A()) X x2 = B(); // calls X::X(B(),so
我有一个程序需要将异常从任何未被捕获的线程传播到主线程,以便它可以向用户提供有关失败原因和安全关闭的信息.我的InterThreadException处理程序似乎工作,但只有当引发异常的线程由主线程直接生成时. 在所有情况下都会正确调用InterTheadException处理程序,通过向其传递异常指针来通知传播异常,并且主线程接收到它已收到新异常的通知,但调用std :: rethrow_exc
在C 11标准中,有一个关于支持统一初始化的阵列的说明,其中指出: The implementation is free to allocate the array in read-only memory if an explicit array with the same initializer could be so allocated. GCC/C++lang / VS会利用这个吗?或者使用
我想要防止甚至隐藏基类非虚函数一段时间,因为我学习了C,我不确定这是否符合道德规范,但C 11特性给了我一个想法.假设我有以下内容: bases.h …. #ifndef baseexample_h #define baseexample_h #include <iostream> class Base{ public: void foo() { std::
我收到了一些非常奇怪的错误.编译器似乎想要因为某些我不理解的原因而调用复制构造函数. (118) std::map<int, layer> xs; (119) xs.begin()->first; // error?! 图层是不可复制的可移动类型. class layer : public observable { layer(const layer&); layer& opera
让我们考虑下面的代码 pollfd file_descriptors[1]; file_descriptors[0].fd = sock_fd; file_descriptors[0].events = POLLIN; int return_value = poll(file_descriptors, 1, 0); if (return_value == -1) { cerr << strer
我在实验室工作并使用std :: thread在C 11上编写了多线程计算程序.现在我有机会在多CPU服务器上运行我的程序. 服务器: >运行Ubuntu服务器 >拥有40个Intel CPU 我对多CPU编程一无所知.我想到的第一个想法是运行40个应用程序然后将它们的结果粘合在一起.这是有可能的,但我想更多地了解我的机会. >如果我通过它的gcc编译器在服务器上编译我的代码,结果应用程序是否利用
我刚刚学习了这个因为 this question,std :: complex的标准状态(26.4 [complex.numbers]): 4 If z is an lvalue expression of type cv std::complex<T> then: — the expression reinterpret_cast<cv T(&)[2]>(z) shall be well-for