mercredi 8 janvier 2020

how to check if a class has an operator []?

I'm trying to check if operator [] overloaded in some class. There is my code:

template <class T, class = void>
struct has_operator : std::false_type {};

template <class T>
struct has_operator < T,
            std::void_t<decltype(std::declval<T>[](int i))>> :
            std::true_type {};

But it doesn't work actualy.

I'm trying to write like code witch cheking if class has operator ()

here it's :

template <typename T,class=void>
struct callable_without_args: std::false_type{};

template <typename T>
struct callable_without_args<T
          ,std::void_t<decltype(std::declval<T>()())>>
  :std::true_type{};

Aucun commentaire:

Enregistrer un commentaire