I am trying to control the access to non-const member functions from a singleton. I maintain a typelist of all classes which have are allowed to access the non-const member functions of a singleton. I am planning to use BOOST_TYPEOF(this) to detect at compile time if the class is present in the typelist. However, this check is invalid from a static member function or a non-class functions. Is there a way to detect this at compile-time.
class A;
class B;
class C;
class Singleton{
....
public:
typedef LOKI_TYPELIST_2(ClassA, classB) allowed_list;
void doF_modify();
void doF() const;
}
#define set_pointer_check(A, TypeOfA) if(Loki::TL::IndexOf<Singleton::allowed_list, \
BOOST_TYPEOF(this)>::value == -1)\ //No non-const
std::static_assert(Loki::IsSame<BOOST_TYPEOF(A), \
const\
TypeOfA*>::value);
void A::doF() {
A* ptr;
set_pointer_chec(ptr, A);
}
void B::doF() {
B* ptr;
set_pointer_chec(ptr, B);
}
void C::doF() {
C* ptr;
set_pointer_chec(ptr, C);
}