boost::filesystem::directory_iterator copy-ctor 隐式删除
Posted
技术标签:
【中文标题】boost::filesystem::directory_iterator copy-ctor 隐式删除【英文标题】:boost::filesystem::directory_iterator copy-ctor implictly deleted 【发布时间】:2011-12-23 02:19:59 【问题描述】:boost::filesystem::directory_iterator
reference (v1.48) 说directory_iterator
明确定义了一个复制构造函数。我只是看了the code 并没有,大概是让编译器定义了copy-ctor。
编译器会为该类型生成一个 move-ctor,然后发现隐式 copy-ctor 格式错误,从而删除 copy-ctor 的情况是否会发生?我还没有在一个简单而简洁的代码 sn-p 中重现它,但它似乎是我的代码中正在发生的事情,使用 2011 年 12 月 17 日的 gcc 4.7 快照。我在 gcc 4.6.1 中没有这个问题。
以下是 gcc 4.7 中的错误:
In file included from /usr/local/include/boost/iterator/interoperable.hpp:13:0,
from /usr/local/include/boost/iterator/iterator_facade.hpp:11,
from /usr/local/include/boost/filesystem/v3/path.hpp:28,
from /usr/local/include/boost/filesystem/path.hpp:31,
from /Users/matan/Development/ouch.git/src/include/ouch/operations.hh:4,
from /Users/matan/Development/ouch.git/src/libouch/operations.cc:1:
/usr/local/include/boost/type_traits/is_convertible.hpp: In instantiation of 'const bool boost::detail::is_convertible_basic_impl<boost::filesystem3::directory_iterator&, boost::filesystem3::directory_iterator>::value':
/usr/local/include/boost/type_traits/is_convertible.hpp:296:272: required from 'const bool boost::detail::is_convertible_impl<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator>::value'
/usr/local/include/boost/type_traits/is_convertible.hpp:419:47: required from 'struct boost::is_convertible<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator>'
/usr/local/include/boost/mpl/aux_/nested_type_wknd.hpp:26:31: required from 'struct boost::mpl::aux::nested_type_wknd<boost::is_convertible<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator> >'
/usr/local/include/boost/mpl/aux_/preprocessed/gcc/or.hpp:48:8: required from 'struct boost::mpl::or_<boost::is_convertible<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator>, boost::is_convertible<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator>, mpl_::bool_<false>, mpl_::bool_<false>, mpl_::bool_<false> >'
/usr/local/include/boost/iterator/detail/enable_if.hpp:68:12: required from 'struct boost::iterators::enable_if<boost::mpl::or_<boost::is_convertible<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator>, boost::is_convertible<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator>, mpl_::bool_<false>, mpl_::bool_<false>, mpl_::bool_<false> >, bool>'
/usr/local/include/boost/iterator/iterator_facade.hpp:67:12: required from 'struct boost::detail::enable_if_interoperable<boost::filesystem3::directory_iterator, boost::filesystem3::directory_iterator, bool>'
/usr/local/include/boost/iterator/iterator_facade.hpp:837:323: required by substitution of 'template<class Derived1, class V1, class TC1, class Reference1, class Difference1, class Derived2, class V2, class TC2, class Reference2, class Difference2> typename boost::detail::enable_if_interoperable<Derived1, Derived2, typename boost::mpl::apply2<boost::detail::always_bool2, Derived1, Derived2>::type>::type boost::operator!=(const boost::iterator_facade<Derived1, V1, TC1, Reference1, Difference1>&, const boost::iterator_facade<Derived2, V2, TC2, Reference2, Difference2>&) [with Derived1 = boost::filesystem3::directory_iterator; V1 = boost::filesystem3::directory_entry; TC1 = boost::single_pass_traversal_tag; Reference1 = boost::filesystem3::directory_entry&; Difference1 = long int; Derived2 = boost::filesystem3::directory_iterator; V2 = boost::filesystem3::directory_entry; TC2 = boost::single_pass_traversal_tag; Reference2 = boost::filesystem3::directory_entry&; Difference2 = long int]'
/usr/local/include/boost/filesystem/v3/operations.hpp:691:49: required from here
/usr/local/include/boost/type_traits/is_convertible.hpp:137:49: error: use of deleted function 'boost::filesystem3::directory_iterator::directory_iterator(const boost::filesystem3::directory_iterator&)'
In file included from /usr/local/include/boost/filesystem/operations.hpp:31:0,
from /Users/matan/Development/ouch.git/src/libouch/operations.cc:4:
/usr/local/include/boost/filesystem/v3/operations.hpp:581:9: note: 'boost::filesystem3::directory_iterator::directory_iterator(const boost::filesystem3::directory_iterator&)' is implicitly deleted because the default definition would be ill-formed:
/usr/local/include/boost/filesystem/v3/operations.hpp:581:9: error: use of deleted function 'boost::shared_ptr<boost::filesystem3::detail::dir_itr_imp>::shared_ptr(const boost::shared_ptr<boost::filesystem3::detail::dir_itr_imp>&)'
【问题讨论】:
你能发布一些导致错误发生的代码吗? 我在 GCC 5.1 和 Clang 3.8 中遇到了这个问题,可能是因为我使用的是过时的 Boost 1.46.1 【参考方案1】:是的,字体可以轻松移动但不可复制。例如,如果它有一个不可复制但可移动的成员或基类。在 C++11 中,这可能是一个 std::fstream。
在这种情况下,编译器可以为您的类创建一个移动构造函数,但会将复制构造函数声明为已删除。
【讨论】:
以上是关于boost::filesystem::directory_iterator copy-ctor 隐式删除的主要内容,如果未能解决你的问题,请参考以下文章