mercredi 18 mars 2020

Check if method is implemented in CRTP using template of template

This is my code:

template <typename T>
class has_foo
{
    typedef char one;
    struct two { char x[2]; };

    template <typename C> static one test( typeof(&C::foo) ) ;
    template <typename C> static two test(...);

public:
    enum { value = sizeof(test<T>(0)) == sizeof(char) };
};

template<template<class, class > class D, class A, class B>
class Base {
public:
    Base() {
        static_assert(!has_foo<D<A,B>>::value, "error");
    }
};

template<class A, class B>
class Child: public Base<Child, A, B> {
public:
    Child() {
    }
    A foo1(const B& b) {
        return b->bar();
    }
};

I want to check in base if the method foo is implemented in Child. This code should fail but it works actually so I guess my static assert is wrong. Any tips?

Aucun commentaire:

Enregistrer un commentaire