Reputation: 638
There are numerous resources explaining how to do Type aliasing, but clearly I am missing something. I am trying to create a map alias. When debugging I want my Map_t
to be the standard library map
since it is easier to see what it contains, and when not debugging I want it to be btree::btree_map
since it uses less memory.
To do this I tried the following:
#if DEBUG
#include <map>
template<typename U, typename V>
using Map_t = map<typename U, typename V>; // <--- Error on this line
#else
#include "btree_map.h"
template<typename U, typename V>
using Map_t = btree::btree_map<typename U,typename V>; // <--- Error on this line
#endif
When compiling I get the error error: expected unqualified-id before 'using'
. I've tried several variations of the above with no success. Thanks in advance for your comments.
UPDATE: I feel I may have made this a little confusing be including the btree portion. SO let me expand a little. If I declare my types as say either
btree::btree_map<int, int> mymap;
or
map<int, int> mymap;
all is fine. But just trying to introduce
template<typename U, typename V>
using Map_t = map<U, V>;
Map_t<int, int> mymap;
leads the the error.
Upvotes: 1
Views: 3991
Reputation: 227400
Your syntax is slightly wrong. You need
template<typename U, typename V>
using Map_t = map<U, V>;
As for the btree
segment, it depends on the details of btree
. If it is a namespace with a class template called btree_map
, then you need
template<typename U, typename V>
using Map_t = btree::btree_map<U, V>;
If it is a class template with an inner type, then you may need something like
template<typename U, typename V>
using Map_t = typename btree<U,V>::btree_map;
Upvotes: 1