boost :: filesystem :: directory_iterator copy-ctor被删除

时间:2011-12-23 02:19:59

标签: c++ boost

boost::filesystem::directory_iterator reference(v1.48)说directory_iterator明确定义了一个拷贝构造函数。我只是看了the code但它没有,可能是让编译器定义了复制器。

在编译器为该类型生成move-ctor的情况下是否会出现这种情况,随后会发现隐式copy-ctor会形成错误,从而删除copy-ctor?我还没有在一个简单而简洁的代码片段中重现它,但它似乎是我的代码中正在发生的事情,从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>&)'

1 个答案:

答案 0 :(得分:0)

是的,一种类型可以轻松移动但不可复制。例如,如果它具有不可复制但可移动的成员或基类。在C ++ 11中,它可以是std :: fstream。

在这种情况下,编译器可以为您的类创建一个移动构造函数,但会将复制构造函数声明为已删除。