www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Passing Template to Function

reply Vino <vino.bheeman hotmail.com> writes:
Hi All,

  Request you help on the below program as it error out with the 
below error

UDictCompression.d(31): Error: template UDictCompression.compress 
cannot deduce function from argument types !()(string), 
candidates are:
UDictCompression.compress(T)(Array!T col)

import std.algorithm: countUntil, joiner, sort, uniq, map;
import std.csv: csvReader;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;
import std.meta: AliasSeq;
import std.container.array;

alias ColumnTypes = AliasSeq!(string, string, int);
alias Arr(T) = Array!T;

auto readData() {
auto file = 
File("C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\TColRead.csv", "r");
Arr!(Tuple!ColumnTypes) res;
foreach (record; 
	{ res.insertBack(record); }	
	return res;

auto compress(T)(Array!T col) {
     Arr!int ks; Array!T vals;
	ks.insertBack(col.map!(v => vals.countUntil(v)));
	return tuple(vals, ks);

void main() {
	auto columns = readData[];
	foreach(r; columns)
		foreach(i, ColT; ColumnTypes) {
			auto vk = compress(r[i]);
			writeln(vk[0][], vk[1][]);

Jan 06
parent Vino <vino.bheeman hotmail.com> writes:
On Saturday, 6 January 2018 at 15:26:30 UTC, Vino wrote:
 Hi All,

  Request you help on the below program as it error out with the 
 below error

Hi All, Thank you was able to resolve the issue. From, Vino.B
Jan 07