I always only see enable_if is used with the condition std::is_integral::value.
Is there a way to use in the condition a function-call of a memberfunction of an object of another templateclass? The function I'm talking about should look like this:
bool someFunc()
{
if (QString(T::staticMetaObject.className()) == QString("Form")) {
return true;
}
return false;
}
Currently I cannot get it compiled no matter what I try.
Thank you for helping me.
edit:
that my question is more clear more code and an error msg.
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <type_traits>
#include <QDebug>
template <class T>
typename std::enable_if<Form<MainWindow>::staticThis->someFunc(),bool>::type
is_smth (T* obj) { return true; }
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
form = new Form<MainWindow>;
qDebug() << is_smth(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "form.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
Form<MainWindow>* form;
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
form.h
#ifndef FORM_H
#define FORM_H
#include <QObject>
class FormBase : public QObject
{
Q_OBJECT
};
template <class T>
class Form : public FormBase
{
public:
Form() {}
static Form* staticThis;
bool someFunc()
{
if (QString(T::staticMetaObject.className()) == QString(Form::staticMetaObject.className())) {
return true;
}
return false;
}
};
#endif // FORM_H
form.cpp
#include "form.h"
#include "mainwindow.h"
Form<MainWindow>* Form::staticThis = NULL;
error:
the value of 'Form::staticThis' is not usable in a constant expression typename std::enable_if::staticThis->someFunc(),bool>::type ^
I'm do not want to use in condition of enable_if a function from std or something. I want to use my own function. And i don't know how to get it work. Maybe thats why you will think the code is a little bit busy. But i think it should show now what I'm trying to accomplish.
Thank you again