On Thu, 23 Oct 2014 05:13:14 GMT, Jack Applegame wrote:

On Thu, 23 Oct 2014 02:01:07 GMT, Domingo Alvarez Duarte wrote:

Hello !

I'm trying to write a function that accepts a mongodb collection cursor as parameter but I do not know how to do that as cursor is a template type.

Can anyone give some help on this ?
You can use template too:

protected void sendCollectionListAsDataArrayJson2(T)(T collection_list, HTTPServerResponse res, in string[] fields) {
...
}

I'd also usually recommend to just look at a MongoCursor as a general input range to make the code more generic:

import std.range : isInputRange;

protected void sendCollectionListAsDataArrayJson2(R)(R collection_list, HTTPServerResponse res, in string[] fields)
	if (isInputRange!R)
{
	...
}

alternatively, you can also specialize the template to only accept MongoCursor to make the code more specific and to document/enforce correct usage:

import std.traits: isInstanceOf;

protected void sendCollectionListAsDataArrayJson2(R)(R collection_list, HTTPServerResponse res, in string[] fields)
	if (isInstanceOf!(MongoCursor, R))
{
	...
}