2015-04-07 55 views
1

我想通过在http://dlang.org/library/std/array/by_pair.html在d使用byPair

给出的例子中工作,但我不断收到错误Error: no property 'byPair' for type 'int[string]'

有什么我需要进口,我不是?

import std.stdio; 
import std.string; 
import std.array; 
import std.file; 
import std.conv; 
import std.regex; 
import std.typecons : tuple, Tuple; 
import std.algorithm : sort; 

void main(string[] args) 
{ 

     auto aa = ["a": 1, "b": 2, "c": 3]; 
     Tuple!(string, int)[] pairs; 

     // Iteration over key/value pairs. 
     foreach (pair; aa.byPair) 
     { 
      pairs ~= pair; 
     } 

     // Iteration order is implementation-dependent, so we should sort it to get 
     // a fixed order. 
     sort(pairs); 
     assert(pairs == [ 
      tuple("a", 1), 
      tuple("b", 2), 
      tuple("c", 3) 
     ]); 
} 

回答

0

byPair是不相关联的阵列的固有特性。 您需要导入std.array : byPair或只需std.array

我想,因为std.array文档中显示的例子,假设用户将导入std.array

+0

我不好,我确实输入了它。仍然有问题。 – StillLearningToCode