ICode9

精准搜索请尝试: 精确搜索
  • c-引发异常时不调用Move构造函数2019-10-11 22:10:02

    我有一个变量,它会累积当前异常,并且在抛出当前异常时需要清除该变量(这样就不会再次报告相同的错误).问题是抛出std :: move(ex);不调用move构造函数(这将清除ex),而是调用一个复制构造函数(这样ex也会保留已引发的错误). MVCE遵循: #include <iostream> #include <stdexcept> #in

  • c-如何编写此派生类的移动分配函数?2019-10-10 12:07:37

    Due to this bug in Visual Studio 2013,我需要为派生类提供自己的移动构造函数和移动分配.但是,我不知道如何为基类调用适当的move函数. 这是代码: #include <utility> // Base class; movable, non-copyable class shader { public: virtual ~shader() {

  • c – 成员函数.begin()和std :: begin()2019-10-08 14:07:26

    在rvalues上调用std :: vector和std :: begin()的成员函数.begin()会产生不同的输出,如下面的测试所示: vector<int> a{ 1, 2, 3 }; vector<int>::iterator it1 = move(a).begin(); // OK vector<int>::const_iterator it2 = move(a).begin(); // OK vector<int>::iterator i

  • c – 返回活动对象的值2019-10-04 12:15:02

    早在2010年,Herb Sutter主张在Dobb博士的article中使用活性物体而不是裸线. 这是一个C 11版本: class Active { public: typedef std::function<void()> Message; Active(const Active&) = delete; void operator=(const Active&) = delete; Active() : done(fal

  • c – 函数double到std :: move?2019-10-02 20:07:11

    假设我有一个只有一个构造函数的类: class T { public: T(BigClass&& big) : big(std::move(big)) {} ... SomeBigClass }; 在大多数地方,构造函数在temporaries上调用,但在一个地方我需要制作BigClass的显式副本,因为它不是临时的,并且将在循环中多次使用: void foo(cons

  • c – 为什么std :: move采用前向引用?2019-10-01 03:06:22

    std :: move的实现基本上如下所示: template<typename T> typename std::remove_reference<T>::type&& move(T&& t) { return static_cast<typename std::remove_reference<T>::type&&>(t); } 请注意,std :: move的参数是通用引用(也称为转发引用,但

  • c – 左值参考绑定的左值2019-09-30 10:08:24

    编译器一直在抱怨我试图将左值绑定到右值引用,但我看不出如何.我是C 11的新手,移动语义等,所以请耐心等待. 我有这个功能: template <typename Key, typename Value, typename HashFunction, typename Equals> Value& FastHash<Key, Value, HashFunction, Equals>::operator[](Key&

  • c – 为什么在std :: vector的初始化列表中调用复制构造函数?2019-09-29 05:15:08

    我有以下非常简单的课程: class Foo { public: Foo() {} Foo(const Foo&) = delete; Foo(Foo&&) {} void operator=(const Foo&) = delete; void operator=(Foo&&) {} void dump() const {} }; 该类是可构造和可分配的,但不是可复制的可分配的. 我想使用vector的初

  • c – 返回时是否保证移动对象?2019-09-27 06:05:39

    我知道当按值将对象传递给函数时,如果存在构造函数,则始终调用移动构造函数,假设没有复制省略.如何按值返回对象? 例如,假设我们有一个具有移动构造函数的类Foo,并且我们有一个返回Foo对象的函数. Foo g() { Foo f; // do something with f return f; } 如果我们假

  • c – 在移动赋值和移动构造函数方面实现std :: swap2019-09-27 00:05:36

    这是std :: swap的可能定义: template<class T> void swap(T& a, T& b) { T tmp(std::move(a)); a = std::move(b); b = std::move(tmp); } 我相信 > std :: swap(v,v)保证没有效果 > std :: swap可以如上实现. 以下引用似乎暗示这些信念是矛盾的. 17.6.4.9函数参数[res.on.

  • c – 向量中的不可复制元素2019-09-26 09:05:21

    我有一个不可复制的类(即复制构造函数和赋值运算符标记为’删除’).我想将它们保存在std :: vector中. 它是一个RAII类,所以简单地存储指针或引用它不是我想要的. 我对新的初始化列表的了解&移动构造函数有点受限,这可能吗?解决方法:是的,你可以有std :: vector< NotCopyable>如果No

  • c – 默认移动构造函数/赋值和已删除的复制构造函数/赋值2019-09-23 21:15:33

    根据标准, If the definition of a class X does not explicitly declare a move constructor, one will be implicitly declared as defaulted if and only if — X does not have a user-declared copy constructor, — X does not have a user-declared copy assignment opera

  • c – 一个`= default`移动构造函数是否等同于成员移动构造函数?2019-09-23 09:06:40

    这是 struct Example { int a, b; Example(int mA, int mB) : a{mA}, b{mB} { } Example(const Example& mE) : a{mE.a}, b{mE.b} { } Example(Example&& mE) : a{move(mE.a)}, b{move(mE.b)} { } Example& operat

  • c – std :: function的仅移动版本2019-09-18 21:14:52

    因为std :: function是可复制的,所以标准要求用于构造它的callables也是可复制的: n337(20.8.11.2.1) template<class F> function(F f); Requires: F shall be CopyConstructible. f shall be Callable (20.8.11.2) for argument types ArgTypes and return type R. The copy con

  • c – 标准库对自动分配的保证是什么?2019-09-17 01:05:15

    C 11标准对标准库相关的自动分配有什么看法?更具体的是,什么,如果有的话,保证selfAssign的作用是什么? template<class T> std::vector<T> selfAssign(std::vector<T> v) { v = std::move(v); return v; } 解决方法:17.6.4.9函数参数[res.on.arguments] 1 Each of the follow

  • c – 在基于范围的for循环中使用转发引用有什么好处?2019-09-15 16:07:35

    const auto&如果我想执行只读操作就足够了.但是,我已经碰到了 for (auto&& e : v) // v is non-const 最近几次.这让我想知道: 在auto& amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp;或const auto&

  • c – 什么是移动语义?2019-09-10 23:05:29

    我刚刚听完关于C++0x的软件工程无线电podcast interview with Scott Meyers.大多数新功能对我来说都很有意义,我现在对C 0x感到兴奋,除了一个.我仍然没有得到移动语义……究竟是什么?解决方法:我发现用示例代码理解移动语义最容易.让我们从一个非常简单的字符串类开始,该类只保存指

  • c – 为什么`std :: stringstream :: stringstream(std :: string \u0026\u0026)`不存在?2019-09-10 21:05:26

    我希望stringstream有一个构造函数可以从字符串&&中窃取它的初始内容. STL中通常不存在这样的种间“移动构造函数”吗?如果没有,为什么不呢?解决方法:有历史,这是令人失望的.但也是一个看起来光明的未来. 当移动语义进入C 11时,它是巨大的,有争议的,并且势不可挡.我希望能够将字符串

  • c – 幕后的push_back()和emplace_back()2019-09-10 14:06:55

    我目前正在学习C语言,我很好奇push_back()和emplace_back()是如何工作的.当你试图构造并将一个大对象推送到容器的后面时,我总是假设emplace_back()更快,就像向量一样. 假设我有一个Student对象,我想要附加到学生矢量的背面. struct Student { string name; int student_ID;

  • C11中返回const值类型对移动语义的影响2019-09-01 03:16:05

    我不清楚返回的const值对C 11中移动语义的影响. 这两个返回数据成员的函数有什么区别吗?在C 11中,const仍然是多余的吗? int GetValueA() { return mValueA; } const int GetValueB() { return mValueB; } 这些功能怎么样? int GetValuesAB() { return mValueA + mValueB; } const

  • C/C++:使用函数返回的向量的有效方法2019-09-01 00:15:34

    假设我们有一个名为V of vector vector< int>的向量.这是一个班级的私人成员. 我们也有这个类的公共功能: vector<int> getV(){ return V; } 现在,如果我有这个类的一个实例,我想做的就是读取值并找到向量中所有值的总和, 我可以这样说: MyClass obj; //update vector size_t

  • c – 使用boost :: pool_allocator时不调用Move构造函数2019-08-30 08:06:16

    我有以下简单的测试代码. #include <stack> #include <iostream> #include "boost/pool/pool_alloc.hpp" struct Frame { uint32_t i{}; Frame(uint32_t _i) : i(_i) {} Frame(const Frame& f) { std::cout << "Copy c

  • c – 在地图中插入对象而不复制对象2019-08-29 09:14:50

    如果对象的类已禁用复制构造函数和禁用的复制操作符,是否可以在映射中插入对象?移动语义在这里有用吗? #include <map> class T { public: T(int v): x(v) {}; private: T(const T &other); // disabled! T &operator=(const T &other); // disabled! int x; }; int main(

  • c – 只是添加析构函数,什么也不做会导致编译错误(围绕std :: move),为什么?2019-08-28 19:05:45

    当我学习std :: move时,我发现了一个奇怪的问题. 如果我只添加一个对完美程序无效的析构函数,我将收到编译错误. #include <iostream> using namespace std; class M { public: int database = 0; M &operator=(M &&other) { this->database = other.database; othe

  • C 11是否保证一个垂死的物体会被移动而不是复制为一个参数?2019-08-28 16:05:26

    #include <vector> using namespace std; void f(const vector<int>&) {} void f(vector<int>&&) {} int main() { { vector<int> coll; // // coll is dying, so, // "f(coll)" will

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有