Add a template constraint to the second template like so:
bool isPalindrome(Range)(Range r)
if (!isArray!Range)
You will need to import std.traits
for the isArray
template.
If you want to use only the second template you will have to import std.array
which uses UFCS
(Uniform Function Call Syntax) to enable arrays to have the front
, popFront
, empty
, etc, functionality.
UFCS basically means that:
int[] x;
int f = x.front;
Is translated into:
int f = front(x);
front
and others are defined for arrays in std.array
, which enables you to use arrays as if they are ranges. You can use the same technique for your own types. You can define the range functions such as front
inside a struct/class, or you can define them externally as functions which take your struct/class as their first paramater.
See the docs for std.range for more info.