#include <iostream>
#include <map>
#include <typeinfo>

struct Access {
   
    static std::map<int, int> bits;
 
    enum class Group1 : short {
        Right1  = 1 << 0,
        Right2  = 1 << 1,
        Key = 1
    };
   
 
    enum class Group2: short {
        Right1  = 1 << 0,
        Right2  = 1 << 1,
        Key = 2
    };
 
    template<typename T>
    bool operator()(T bit)
    {
    	std::cout << "T: " << typeid(T).name() << std::endl;
        return ((Access::bits.find(static_cast<int>(T::Key)) != Access::bits.end()) && (Access::bits[static_cast<int>(T::Key)] & bit) == bit);
    }

    //bool operator()(Access::Group1 bit);
    //bool operator()(Access::Group2 bit);
 
    Access operator=(std::map<int, int> rights)
    {
        Access::bits = rights;
        return *this;
    }
} Access;
 
std::map<int, int> Access::bits;
 
// Bitvergleich Template
template<typename T>
T operator &(int lhs,  T rhs)
{
    return static_cast<T>(lhs & static_cast<int>(rhs));
}

/*
bool Access::operator()(Access::Group1 bit)
{
    return ((Access::bits.find(static_cast<int>(Access::Group1::Key)) != Access::bits.end()) && (Access::bits[static_cast<int>(Access::Group1::Key)] & bit) == bit);
}
 
bool Access::operator()(Access::Group2 bit)
{
    return ((Access::bits.find(static_cast<int>(Access::Group2::Key)) != Access::bits.end()) && (Access::bits[static_cast<int>(Access::Group2::Key)] & bit) == bit);
}
*/

int main(int argc, char *argv[]) {
   
    // Diese Daten kommen aus der JSON Datei/Anfrage
    std::map<int, int> json = {
        {1, 7}
    };
   
    Access = json;
 
    if (Access(Access::Group1::Right1))
    {
        std::cout << "Access Group1::Right1 granted!" << std::endl;
    }
 
    if (Access(Access::Group1::Right2))
    {
        std::cout << "Access Group1::Right2 granted!" << std::endl;
    }
 
   
    if (Access(Access::Group2::Right1))
    {
        std::cout << "Access Group2::Right1 granted!" << std::endl;
    }
 
    return 0;
}