2015-04-07 24 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