d - 范围从 D 2 中的关联数组

标签 d associative-array

在阅读了 Andrei 的书后,我刚刚开始在 D 2.0 中实现我的第一个中等规模的程序 D 编程语言 .我遇到的第一个问题是使用带有内置关联数组的 std.algorithm 库。例如:

#!/usr/bin/env rdmd

import std.stdio;
import std.algorithm;

void main()
{
   alias int[string] StringHashmap;

   StringHashmap map1;
   map1["one"] = 1;
   map1["two"] = 2;
   writefln("map1: %s", map1);

   StringHashmap map2;
   map2["two"] = 2;
   map2["three"] = 3;
   writefln("map2: %s", map2);

   auto inter = setIntersection(map1, map2);
}
对我来说,这似乎是一件很简单的事情,期望在 inter 上迭代会产生单个“两个”条目。但是,我收到此编译器错误:

./test.d(20): Error: template std.algorithm.setIntersection(alias less = "a < b",Rs...) if (allSatisfy!(isInputRange,Rs)) does not match any function template declaration

./test.d(20): Error: template std.algorithm.setIntersection(alias less = "a < b",Rs...) if (allSatisfy!(isInputRange,Rs)) cannot deduce template function from argument types !()(int[string],int[string])


我可以看到内置关联数组似乎没有提供与 std 算法一起使用的范围的任何版本。
我错过了什么吗?做错事了吗?如果没有,这是一个明显的遗漏吗?有什么原因为什么这不可用吗?

最佳答案

用这个:

auto inter = setIntersection(map1.keys, map2.keys);

关于d - 范围从 D 2 中的关联数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3435652/

相关文章:

javascript - 在关联数组上的 for in 迭代的控制台输出末尾未定义,JavaScript?

javascript - 带有 d3.js 和关联数组的条形图

c++ - 在 MFC 中实现类似 bool 表的结构

monodevelop - Mono-D DMD 编译器问题

d - D 程序中的语法与 R 中的 set.seed (1234)"相同

garbage-collection - d 垃圾收集器和实时应用程序

php - 关联到 PHP 中的数值数组

D:函数参数名称自省(introspection)

d - 从 D 调用 C# 程序

awk 关联数组增长很快