So i've got a bunch of shared_ptr's each pointing to a different template Cache classes. Like so:
shared_ptr< Cache > t1Cache;
shared_ptr< Cache > t2Cache;
shared_ptr< Cache > t3Cache;
Each Cache class simply holds a map with a string as a key and T as the item. I want to have a single function for an update,add and get operations. So I could call for example:
auto something = getItem( key1, TYPE_T1 ); addItem( key2, TYPE_T1, newItem ); updateItem( key3, TYPE_t1, newValue);
I tried at first just having a switch based on the enum like so:
template auto addItem( const std::string& key, ITEM_TYPE type, T nItem )
{ switch( type ) { case TYPE_T1: t1Cache->addItem( key, nItem ); break; case TYPE_T2: t2Cache->addItem( key ,nItem ); break; }
}
Unfortunately I have a basic knowledge of templates so I didn't realize that that will not work. At the moment as a temporary solution im just using a different function for each type, though i'd really like to consolidate it all into one. I thought that maybe 'constexpr if' will help but it's not supported, is this even possible?