On 22 November 2015 at 17:51, <
sergeik...@gmail.com> wrote:
> Make ability to specify a class from which the template should be inherited
> of.
We already have that ability, by constraining via std::is_base_of.
>
> class I {
> virtual int IMethod();
> };
>
> class II {
> virtual bool IMethod();
> };
>
> template <class T, class IT : I> // here we specify that T should be
> inherited from I (directly/undirectly/castable - under consideration (TBD))
> void T fn(const IT& t) {
> return t.IMethod();
> }
In other words,
#include <type_traits>
template <class D, class B> concept bool Derives()
{
return std::is_base_of<B, D>::value;
}
class I {
public:
virtual int IMethod() const = 0;
};
template <class T, class IT>
T fn(const IT& t) requires Derives<IT, I>() {
return t.IMethod();
}
class CT : public I
{
public:
int IMethod() const {return 42;}
};
int main()
{
CT ct;
fn<int>(ct);
}
See live demo here
http://melpon.org/wandbox/permlink/zYSSJ8yK6GRLYxgf