<tfoot id='6UHlO'></tfoot>

  • <legend id='6UHlO'><style id='6UHlO'><dir id='6UHlO'><q id='6UHlO'></q></dir></style></legend>

        <bdo id='6UHlO'></bdo><ul id='6UHlO'></ul>

      <small id='6UHlO'></small><noframes id='6UHlO'>

      <i id='6UHlO'><tr id='6UHlO'><dt id='6UHlO'><q id='6UHlO'><span id='6UHlO'><b id='6UHlO'><form id='6UHlO'><ins id='6UHlO'></ins><ul id='6UHlO'></ul><sub id='6UHlO'></sub></form><legend id='6UHlO'></legend><bdo id='6UHlO'><pre id='6UHlO'><center id='6UHlO'></center></pre></bdo></b><th id='6UHlO'></th></span></q></dt></tr></i><div id='6UHlO'><tfoot id='6UHlO'></tfoot><dl id='6UHlO'><fieldset id='6UHlO'></fieldset></dl></div>

      1. 正确使用 Eigen::Ref&gt;班级

        Correct usage of the Eigen::Reflt;gt; class(正确使用 Eigen::Refgt;班级)

        1. <small id='pAXgD'></small><noframes id='pAXgD'>

        2. <legend id='pAXgD'><style id='pAXgD'><dir id='pAXgD'><q id='pAXgD'></q></dir></style></legend>
              <tbody id='pAXgD'></tbody>
            <i id='pAXgD'><tr id='pAXgD'><dt id='pAXgD'><q id='pAXgD'><span id='pAXgD'><b id='pAXgD'><form id='pAXgD'><ins id='pAXgD'></ins><ul id='pAXgD'></ul><sub id='pAXgD'></sub></form><legend id='pAXgD'></legend><bdo id='pAXgD'><pre id='pAXgD'><center id='pAXgD'></center></pre></bdo></b><th id='pAXgD'></th></span></q></dt></tr></i><div id='pAXgD'><tfoot id='pAXgD'></tfoot><dl id='pAXgD'><fieldset id='pAXgD'></fieldset></dl></div>
              <tfoot id='pAXgD'></tfoot>
                • <bdo id='pAXgD'></bdo><ul id='pAXgD'></ul>

                • 本文介绍了正确使用 Eigen::Ref&gt;班级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Eigen 引入了 Ref<> 类来编写带有 Eigen 对象作为参数的函数,而不需要使用不必要的临时变量,当不需要编写模板函数时.您可以在此处阅读有关此内容的信息.

                  Eigen has introduced the Ref<> class to write functions with Eigen objects as parameters without the use unnecessary temporaries, when writing template functions is not wanted. One can read about this here.

                  在 Internet 上进一步搜索时,我发现使用 Ref<> 类声明了几种不同的参数.在 Eigen 文档中,他们使用 const Eigen::Ref& 作为第一个示例中的只读参数.在第二个例子中,Eigen::Ref 被引入用于读写参数,但这里 const Eigen::Refcode> 用于只读参数(无参考).所以我的问题是:

                  When searching the internet further, I found several different declarations of parameters using the Ref<> class. In the Eigen documentation they use const Eigen::Ref<const Eigen::MatrixXf>& for a read-only parameter in the first example. In the second example Eigen::Ref<Eigen::MatrixXd> is introduced for read-and-write parameters, BUT here const Eigen::Ref<const Eigen::MatrixXd> is used for read-only parameters (no reference). So my question is:

                  以下声明有什么区别,我什么时候使用哪个?`

                  What is the difference between the following declarations and when do I use which?`

                  1. const Eigen::Ref&
                  2. const Eigen::Ref
                  3. const Eigen::Ref&
                  4. const Eigen::Ref
                  5. Eigen::Ref&
                  6. Eigen::Ref
                  7. Eigen::Ref&
                  8. Eigen::Ref

                  为了完整起见,我列出了 const 用法和参考的所有可能组合.

                  For completeness I listed every possible combination of const usage and the reference.

                  推荐答案

                  一般来说,使用像 Ref<T>& 这样的非常量引用从来都不是一个好主意,因为这只在以下情况下有效调用者手头已经有一个 Ref 对象.这会丢弃 5 和 7.

                  In general, using a non const reference like Ref<T>& is never a good idea because this will only work if the caller already has a Ref<T> object at hand. This discards 5 and 7.

                  案例 3 和案例 4 没有意义,它们通常不会编译.

                  The cases 3 and 4 does not make sense, and they won't compile in general.

                  那么,const Refconst Ref& 之间没有太大区别,因为函数不太可能是使用现有的 Ref 对象调用,因此无论如何在大多数情况下都必须创建 Ref.尽管如此,我们仍然可以推荐 1 比 2 或 6.

                  Then, there is not much difference between a const Ref<const T> and a const Ref<const T>& because it is unlikely that the function is called with an existing Ref<const T> object, and so a Ref<const T> will have to be created in most cases anyway. Nevertheless, we could still recommend 1 over 2 or 6.

                  总之,我们可以推荐 Ref 作为可写引用,const Ref& 作为常量引用.

                  So in summary, we could recommend Ref<T> for a writable reference, and const Ref<const T>& for a const reference.

                  选项 6,Ref,如果您想通过调用 Ref 构造函数使用 placement new.

                  The option 6, Ref<const T>, might still be interesting if you want to change the matrix that is referenced (not its content) through a call to Ref constructor using placement new.

                  这篇关于正确使用 Eigen::Ref&gt;班级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)

                  <small id='DNt81'></small><noframes id='DNt81'>

                  1. <tfoot id='DNt81'></tfoot>
                    <legend id='DNt81'><style id='DNt81'><dir id='DNt81'><q id='DNt81'></q></dir></style></legend>
                        <tbody id='DNt81'></tbody>

                            <bdo id='DNt81'></bdo><ul id='DNt81'></ul>
                            <i id='DNt81'><tr id='DNt81'><dt id='DNt81'><q id='DNt81'><span id='DNt81'><b id='DNt81'><form id='DNt81'><ins id='DNt81'></ins><ul id='DNt81'></ul><sub id='DNt81'></sub></form><legend id='DNt81'></legend><bdo id='DNt81'><pre id='DNt81'><center id='DNt81'></center></pre></bdo></b><th id='DNt81'></th></span></q></dt></tr></i><div id='DNt81'><tfoot id='DNt81'></tfoot><dl id='DNt81'><fieldset id='DNt81'></fieldset></dl></div>