www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to realize isSortedRange?

reply Alexandr Druzhinin <drug2004 bk.ru> writes:
I need to ensure that range passed to function is SortedRange to use 
binary search. I did something like:

static if(!__traits(compiles,
	{
		ElementType!(typeof(data)) element;
		auto d = data.trisect(element);
	}
	)) assert(0, "DataRange shall be SortedRange");

It works for me, but in fact it checks if the type of 'data' have 
'trisect' method and conception of SortedRange is something more than 
having 'trisect' method.
	I remember there is(?) some way to get general type of template (i.e. 
SortedRange instead of SortedRange!int), but can not find it.
Aug 19 2014
parent reply "Kagamin" <spam here.lot> writes:
http://dlang.org/phobos/std_traits.html#TemplateOf
Aug 20 2014
parent reply "hane" <han.ehit.suzi.0 gmail.com> writes:
On Wednesday, 20 August 2014 at 07:18:12 UTC, Kagamin wrote:
 http://dlang.org/phobos/std_traits.html#TemplateOf
Or isInstanceOf. static if (__traits(isSame, TemplateOf!R, SortedRange)) static if (isInstanceOf!(SortedRange, R))
Aug 20 2014
parent Alexandr Druzhinin <drug2004 bk.ru> writes:
Thank you!
Aug 20 2014