Question: When creating a function template in C++, is it possible to specify something like a generic constraint in C# on a type parameter? For instance this function template makes sense only for types that define `<` and `==` (in C# the signature would be `int Compare<T>(T item1, T item2) where T : IComparable<T>`):

```
template <typename T>
int compare(const T &item1, const T &item2)
{
    if (item1 == item2) return 0;
    if (item1 < item2) return -1;
    if (item2 < item1) return 1;
}

```

Answer: 
It's possible by using boost, but not possible in current standard. There will be concepts lite (in feature) ([read this for more information](https://isocpp.org/blog/2013/02/concepts-lite-constraining-templates-with-predicates-andrew-sutton-bjarne-s)). Now you can only write your own library, use `std::enable_if` or something else, or use [boost concept check library](http://www.boost.org/doc/libs/1_55_0/libs/concept_check/concept_check.htm).
Have a look for SFINAE in general.

in c++11 there are a lot of helping functionality arround SFINAE like enable\_if and a lot of type traits. And yes, you can also check for the existence of a member function of a given type.

The *trick* in general is, that a template declaration while fail but give no error if the failure arises before the definition block.