- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 boost::intrusive::list<Foo, constant_time_size<false>>
, 其中Foo
继承自 list_base_hook<auto_unlink>
钩。带有列表元素 foo
,我可以通过调用 list::s_iterator_to(foo)
来获取它的迭代器.我的问题是如何使用此迭代器遍历列表。特别是,有没有办法判断这个元素是否是列表中的唯一元素?
来源建议list
使用 cicular_list_algorithms
在其值(value)特征中,也许我可以使用以下测试?
auto itr1 = list_t::s_iterator_to(foo);
auto itr2 = list_t::s_iterator_to(foo);
&(*++itr1) == &(*--itr2);
它看起来很老套,但看起来很管用。我不确定它是否正确和惯用。有人可以建议吗?
完整 list :
#include <iostream>
#include <boost/intrusive/list.hpp>
using namespace boost::intrusive;
typedef list_base_hook<link_mode<auto_unlink> > auto_unlink_hook;
class Foo : public auto_unlink_hook
{
int int_;
public:
Foo(int i = 0) : int_(i) {}
int get_int() { return int_; }
void unlink() { auto_unlink_hook::unlink(); }
bool is_linked() { return auto_unlink_hook::is_linked(); }
};
int main()
{
typedef list<Foo, constant_time_size<false>> ListType;
ListType l;
Foo foo1{42};
l.push_back(foo1);
auto itr1 = ListType::s_iterator_to(foo1);
auto itr2 = ListType::s_iterator_to(foo1);
std::cout << (&(*++itr1) == &(*--itr2)) << std::endl;
Foo foo2{43};
l.push_back(foo2);
itr1 = ListType::s_iterator_to(foo1);
itr2 = ListType::s_iterator_to(foo1);
std::cout << (&(*++itr1) == &(*--itr2)) << std::endl;
foo1.unlink();
return 0;
}
是的,我确实实现了取消引用 ++itr1
和 --itr1
是错的。有什么办法可以直接比较底层节点的地址吗?我想foo
具有指向其前任和继任者的两个链接,如果foo
,它们应该彼此相等是唯一的元素。
最佳答案
我尝试了这些,并且有效。但是,它与实现细节紧密结合。思路是从值中获取底层节点指针并比较指针。
typedef list<Foo, constant_time_size<false>> ListType;
ListType l;
Foo foo1{42};
l.push_back(foo1);
ListType::const_node_ptr cur = ListType::value_traits::to_node_ptr(foo1);
std::cout << (ListType::node_traits::get_previous(cur) == ListType::node_traits::get_next(cur)) << std::endl;
Foo foo2{43};
l.push_back(foo2);
std::cout << (ListType::node_traits::get_previous(cur) == ListType::node_traits::get_next(cur)) << std::endl;
关于c++ - boost::intrusive::list with the auto-unlink hook:我可以使用列表中的值来确定列表是否只有一个元素吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48485135/
我的应用程序有一个 ' Photo ' 字段来存储 URL。它使用 sfWidgetFormInputFileEditable对于小部件架构。要在上传新图像时删除旧图像,我在覆盖的 setter 中设
在代码示例中,我有时会发现像这样的行: import android.app.Activity import android.os.Bundle 我在文档中找不到关于此的任何内容。为什么要用这个,有什
我正在使用一个名为 Jquery-Oembed-All 的插件来嵌入来自 soundcloud 的音频。我将轨道名称、年份和 URL 存储在数据库中,经过查询后,音频已嵌入我的网站。我的问题是显示的文
想删除一个产品,删除产品的图片,但又不想缺什么。产品删除正常但不删除图像 if((isset($_GET["remove"])) && ($_GET["remove"] != "")){ $i
PHP unlink() not working to delete files 我的代码在数据库中正确删除,但无法从文件中删除,请问如何帮助我删除上传文件中的数据? Query($strSQL);
我试图预测我可以使用 unlink() 删除哪些文件。 到目前为止,我的理解是该文件必须对其他人可写,或者与执行程序具有相同的组 ID 或所有者 ID。 还有其他情况吗?我正在尝试解释我的程序如何删除
我正在编写进程间通信的代码。 在接收进程代码中我调用了方法 unlink("datapipe"); 我还包含了#include 头文件。 最后我得到了以下错误: receiver.c:12: erro
for($i=0; $i (来源:http://au1.php.net/chdir) 关于php - unlink() 不起作用,我们在Stack Overflow上找到一个类似的问题: https:
我遇到一个问题,如果在清理期间由网络用户打开,用 Java 编写的存档模块无法清理通过 smb 共享的文件。以下是文件清理代码的简化版本: private static boolean mov
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我在通过 unlink() 函数删除文件时遇到问题。当文件使用西里尔文名称时,该功能不起作用。 [24-Jul-2012 00:33:35 UTC] PHP Warning: unlink(/home
好吧,我一直想知道我是否可以正确处理 unlink() 函数。我不希望 unlink() 函数在无法取消链接文件时抛出一些讨厌的错误(可能是由于找不到文件)。 我尝试了类似的东西 try {
最近在写个网站,需要上传图片,如果修改图片,就图片就没有用了,会占用服务器的硬盘资源,所以想到用unlink函数删除旧照片. 问题 : unlink函数只能删除 相对于函数执行文件的相对目录&nb
我正在尝试通过 AJAX 函数取消链接来删除图像,该函数在传递文件路径之前使用encodeURIComponent对文件路径进行编码。但是,我在取消链接时遇到错误,所以我做了一些尝试来查找错误。 当我
我想读取命令行参数中给出的文件并在读取后将其删除。这就是我正在做的事情。 char *filename = argv[1]; char *outputfile = strcat(argv[1], ".
我在使用 featherlight 时遇到了一些问题,由于某种原因它无法正常工作,我正在使用 Ghost 作为平台并且我使用 Ghost 的 Markdown 将几张图片添加到帖子中,为了使 feat
这个问题在这里已经有了答案: 关闭 13 年前。 Possible Duplicate: Deleting files by type in Python on Windows 如何删除目录中所有扩
来自 APUE #include int unlink(const char *pathname); Only when the link count reaches 0 can the conte
我试图在第一次显示后从服务器中删除图片 (.jpg)。但是文件在显示之前被删除(unlink();)。我已经尝试过使用 sleep() 但这只会延迟加载,并且在显示之前删除所有文件。 最佳答案 您可以
我是 Node.js 新手。 const fs = require('fs'); fs.unlink('/tmp/hello', (err) => { if (err) throw err;
我是一名优秀的程序员,十分优秀!