How to convert at::ScalarType to c++ type?

I have a template class have two typename

// key maybe uint32_t or uint64_t, elem can be any interger or float type
template <typename KeyType, typename ElemType>
class Cache{
  // ....
};

I want to use pybind to provide python API for this Cache class. And since pybind API need to specify the KeyType and ElemType. So I need to write a wrapper class like below:

class CacheWrapper{
   CacheWrapper(at::Tensor t, CacheConfig cfg){
         dtype = t.scalar_type();
         if(cfg.capacity > UINT32_MAX){
               lru_cache = reinterpret_cast<void*>(AT_DISPATCH_ALL_TYPES(t.type(), "uint32_cache",[&]{NewUint32LRUCache<scalar_t>(cache, cfg);}));
            }else{
               lru_cache = reinterpret_cast<void*>(AT_DISPATCH_ALL_TYPES(t.type(), "uint64_cache",[&]{NewUint64LRUCache<scalar_t>(cache, cfg);}));
            }
    }
private:
     void* cache;
     at::ScalarType dtype;
};

my question is can I directly use the dtype to instantiate the template class like Cache<uint32_t, dtype>, if not, how can I convert dtype to c++ type;

ScalarTypeToCPPType<scalar_type>.type might do the trick (in c10/core/ScalarType.h).

Best regards

Thomas