【发布时间】:2017-01-03 10:27:27
【问题描述】:
我正在使用以下代码列出目录:
for ( const auto& fileEntry : boost::make_iterator_range( boost::filesystem::directory_iterator( some_directory ), {} ) )
{
const boost::filesystem::path tmpFullName = fileEntry.path();
if ( boost::filesystem::exists( tmpFullName ) &&
boost::filesystem::is_regular_file( tmpFullName ) &&
(boost::filesystem::extension( tmpFullName ) == ".doc") )
{
processFile( tmpFullName.string() );
}
}
我偶尔看到以下错误
/boost/1.47.0/include/boost-1_47/boost/smart_ptr/shared_ptr.hpp:420: T* boost::shared_ptr::operator->() const [with T = boost::filesystem3::detail::dir_itr_imp]: 断言 `px != 0' 失败。
在我的代码中,我没有定义任何 boost shared_ptr 而是只使用 std::unique_ptr。 因此,我认为潜在的问题在于上述列表函数。
有人可以仔细检查一下这个功能,看看这里是否有任何潜在的问题吗?
【问题讨论】:
-
最新版本的Boost是否出现问题?
-
由于内部原因,我无法使用最新版本的Boost
-
请注意,您可以使用较短的版本而无需明确指定范围:
for ( const auto& fileEntry : boost::filesystem::directory_iterator{ some_directory } )。