|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
D - Templates and Associative Arrays
Is it possible to create a template function that treats regular dynamic
arrays the same as associative arrays? For example, I want to create a very
simple template function to extract a column from a 2-d array of T's. If the
array is non-associative in both dimensions, the function could be trivially
implemented as:
T[] extract_column(T)(T[][] data, size_t column_to_extract)
{
T[] extracted_column;
foreach(row; data)
{
extracted_column~=row[column_to_extract];
}
return extracted_column;
}
However, in the case of an associatve array, I cannot think of any obvious way
to make this work without essentially implementing it four different times,
once each for an associative and non-associative row dimension and likewise
for the column dimension.
Jan 20 2008
|