c++11专题提供c++11的最新资讯内容,帮你更好的了解c++11。
假设这是一个要包装的C函数: void foo(int(__stdcall *callback)()); C函数指针回调的两个主要缺陷是: >无法存储绑定表达式 >无法存储捕获羔羊 我想知道包装这些功能的最佳方法.第一个对成员函数回调特别有用,而第二个对于使用周围变量的内联定义,但这些定义不是唯一的用途. 这些特定函数指针的另一个属性是它们需要使用__stdcall调用约定.据我所知,这完全消除了
为什么这不起作用? #include <vector> struct A { template <typename T> void f(const std::vector<T> &) {} }; int main() { A a; a.f({ 1, 2, 3 }); } 您可以初始化std :: vector< T>列表初始化.但是,您不能使用std :: vector
不知怎的,我不知道如何扩展可变的模板参数包.以下代码有什么问题? #include <iostream> template <typename T> struct print_one { static void run(const T& t) { std::cout << t << ' '; } }; template<typename... Args>
有时候,我需要具有无操作删除器的shared_ptr实例,因为API期望一个shared_ptr实例,它希望在有限的时间内存储,但是我被给予一个原始指针,我不允许拥有一个比我正在跑 对于这种情况,我一直在使用一个无操作的删除程序,例如[](const void *){},但是今天我发现还有另一个选择,使用(或滥用) void f(ExpectedClass *ec) { std::share
从cppref所说的约 value initialization if T is a class type with no default constructor or with a user-provided or deleted default constructor, the object is default-initialized; 但由于该类类型已删除默认构造函数,该对象如何进行默认初
我使用SFINAE表达式来测试一个类型是否支持运算符<< namespace details { template<typename T> struct sfinae_true : std::true_type { }; template<typename T> sfinae_true<decltype (std::declval<std::ostream &> () <
使用GCC 6.1,以下程序: #include <string> #include <vector> #include <iterator> #include <algorithm> #include <iostream> int main() { static const std::string foo {"foo"}; std::vector<std::string> ba
我看到这样的声明 typedef *unspecified* value_type; typedef *unspecified* reference; 在Boost :: multi_array类的声明中. namespace boost { template <typename ValueType, std::size_t NumDims, type
看下面的代码: struct node { node(); //node(const node&); //#1 //node(node&&); //#2 virtual //#3 ~node (); node* volatile //#4 next; }; int main
In-class initializers(C 11功能)必须用大括号括起来或按照=符号.它们可能不在括号内指定. 这是什么原因? 我对此不是100%肯定,但这可能是为了防止语法模糊.例如,考虑以下类: class BadTimes { struct Overloaded; int Overloaded; // Legal, but a very strang
在以下C 11代码中,最后一次调用arraySize会导致编译错误.显然这是因为y是一个运行时大小的数组,并且arraySize模板参数N不能被推导出来.我不明白为什么x是一个编译时间大小的数组,但是y结束运行时大小. arraySize模板函数直接从Scott Meyers的“有效现代C”项目1中获取. #include <cstddef> template<typename T, std::
我正在使用g 4.9.1(-std = c 11)来编译具​​有std :: thread,std :: bind和boost :: asio的简单测试程序. 但是,当创建新线程时,它不会编译,当我使用std :: bind.另一方面,当我切换到boost :: bind一切都很好. 以下是代码: #include <iostream> #include <memory> #include <th
我想使用一个std :: atomic_int变量.在我的代码中,我有: #include <atomic> std::atomic_int stop = 0; int main() { // Do something } 这给我一个编译错误: use of deleted function 'std::__atomic_base<_IntTp>::__atomic_base(cons
(首先在“bind”中的问题与std :: bind无关) 我看过Expected<T> talk,我认为这个技术的历史演示文稿缺少了哈斯克尔背后的核心思想. Haskell的核心思想是,您“永远不会”接受“预期”的价值.你所做的是将一个lambda传递给预期的< T>这将根据预期的状态而被施加或不被应用. 我本来希望这个“绑定”组合器是预期的“T”将被使用,所以我必须问这个编程风格是否被拒绝了某
N2976建议在标准库中的某些位置添加constexpr.它注意到iostreams不适用于constexpr EXCEPT结束迭代器.所以istream_iterator和istreambuf_iterator被赋予了constexpr的默认构造函数,就是这样.例如,您可以在 libstdc++ implementation中看到,constexpr仅在整个文件中出现一次.引发这一变化的LWG是
考虑以下愚蠢的例子: class MyClass { public: template <class Function> inline double f(double x, Function&& function) { return function(x); } }; 有了这个类,我可以调用MyCla
这个标题或多或少地说了一切.我有以下一点 的代码: #include <vector> #include <string> #include <iterator> #include <algorithm> struct xloper12; class Something { public: std::string asString() const; }; extern std::vec
我想使用std :: function作为方法的参数,并将其默认值设置为std :: stoi. 我尝试了以下代码: void test(std::function<int(const std::string& str, size_t *pos , int base)> inFunc=std::stoi) 不幸的是我收到以下错误: no viable conversion from '<overl
Arch Linux(i686)上的Clang 3.2用于构建以下C 11代码 #include <iostream> #include <functional> typedef std::function<void ()> Action; typedef std::function<int ()> Generator; Action act(Generator const& gen) {
下面的代码工作在 gcc-4.8.2中 #include <iostream> using namespace std; template<typename... Args> void func(Args... args, int optional = 0) { cout << optional << endl; } int main() { func(1); func