本文介绍了被删除的构造函数“可访问”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 在关于此问题的已删除移动构造函数引号cppreference.com说, is_move_constructible trait应该会成功,只要移动构造函数是可访问的,即使它不是可用。 标准实际上要求参数类型的移动构造格式良好,因此答案不太对。 现在,标准重复使用术语可访问来指代实际可构造性的构造函数。例如: 我错过了一段吗? > 如果没有,是否应该更正cppreference.com页面? >解决方案从问题的第二个引号,我会说,辅助功能不受 delete dness的影响,实际上根本不会覆盖这样的构造函数可能 delete d的情况。 在 delete 的定义中,这种情况被一种全部要求覆盖: [C ++ 11:8.4.3 / 2]:隐式或显式引用被删除函数的程序,声明它,是不成形的。 [注意:这包括隐式或显式地调用函数,并形成一个指向函数的指针或指向成员的指针。它甚至适用于不可能被评估的表达式中的引用。如果一个函数被重载,它只有在通过重载分辨率选择该函数时才被引用。 -end note] 因此,cppreference.com可能会注意到,适用于 is_move_constructible trait的标准,而不仅仅是移动构造函数是否可访问。这里还有一个问题,就是 MoveConstructible 可以通过 CopyConstructible 来满足† ,因此即使移动构造函数本身也不是必须的。 这一切都提出了另一个有趣的点,虽然,任何可能的实现 is_move_constructible 必须引用删除的移动构造函数,呈现该程序不正确,如上述报价所述。仍然,我想用SFINAE的技巧,一个实现可以避免实际上变得不成形。 ; 一个没有移动ctor但是有一个copy-ctor的类型是可移动构造的(可从一个右值构造)。 — DyP A deleted answer on this question about a deleted move constructor quotes cppreference.com as saying that the is_move_constructible trait should succeed as long as a move constructor is "accessible", even if it's not "usable".The standard in fact requires that move-construction of the argument type be well-formed, so the answer was not quite right.Now, the standard repeatedly uses the term "accessible" in relation to constructors referring to actual constructibility. For example:However, I can't find anywhere in the standard that states categorically whether a deleted, explicitly-defined constructor is "accessible" or not.A different [non-normative] quote seems to suggest that deleted-ness and accessibility are orthogonal:Have I missed a passage?If not, should the cppreference.com page be corrected? Can you suggest a better wording?Should the standard be clearer about this either way? 解决方案 From the second quote in the question, I'd say that accessibility is not affected by deletedness, and that the first quote actually doesn't at all cover the case that such a constructor may be deleted.This scenario is instead covered by a sort of "catch-all" requirement in the definition of delete:So, cppreference.com could probably do with a note that there is a further criterion that applies to the is_move_constructible trait, than simply whether the move constructor is accessible. And there's a further problem here, which is that MoveConstructible can be satisfied by CopyConstructible too†, so even the move constructor on its own is not strictly necessary.This all raises another interesting point, though, that any possible implementation of is_move_constructible must surely "refer" to the deleted move constructor, which renders the program ill-formed as stated in the quote above. Still, I suppose with SFINAE tricks an implementation can avoid actually becoming ill-formed.† "A type with no move ctor at all but with a copy-ctor is move-constructible (constructible from an rvalue)." — DyP 这篇关于被删除的构造函数“可访问”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-06 18:49