如何查看所有数据结构依赖性是否已解决?
让我们想象一下演示情况,我们有如此简单的结构
struct service
{
std::string name
std::set<std::string> depends_on_service_name;
};
我们有一些原始数据(文本文件、io 流或什么 ewer)进入我们的解析器,将其转换为服务结构实例并将它们放入 std::map
我们需要一种方法来检查所有地图项是否都已解决depends_on_service_name
(这意味着每个 services[item].name
在地图中应有 services[item].name
代码>服务[other_item].depends_on_service_name)。是否有任何标准方法可以在手动 for_each
的提升中检查此类内容是每次 parser
将新项目附加到地图时的方法?
Lets imagine demo situation that we have such simple structure
struct service
{
std::string name
std::set<std::string> depends_on_service_name;
};
We have some raw data (text file, io stream or what ewer) coming into our parser
that turns it into service struct
instances and puts them into std::map<service> services
we need a way to chack if all map items have all there depends_on_service_name
resolved (meaning there shall be services[item].name
in map for each service[other_item].depends_on_service_name
). Is there any standart way to check for such things in boost of manual for_each
is the way to go each time parser
appends new item(s) into map?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的“方法”是在输入验证和抽象期间解决这个问题。您正在使用服务映射来表示有向(可能是非循环)图,并且您应该这样表示它(例如使用Boost.Graph),而不是使用集合和映射来滚动您自己的图结构。当你构建这个显式的图结构时,缺失的服务自然会被发现。
The "way to go" here is to solve this problem during input verification and abstraction. You are representing a directed (probably acyclic) graph with the service map, and you should represent it as such (e.g. using Boost.Graph) instead of rolling your own graph structure with sets and maps. While you are building this explicit graph structure, missing services will naturally be discovered.