Created
October 9, 2020 07:39
-
-
Save airglow923/3dbae1031ec0fd0cc176e69e5aea35d6 to your computer and use it in GitHub Desktop.
Map wrapper using class template argument deduction (CTAD).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <map> | |
#include <unordered_map> | |
template< | |
template<typename, typename> typename Map, | |
typename K, | |
typename V | |
> | |
class AnyMap { | |
public: | |
template<typename M> | |
AnyMap(const M& m) {} | |
template< | |
template<typename, typename> typename M, | |
typename A, | |
typename B | |
> | |
AnyMap(const M<A, B>& m) {} | |
private: | |
Map<K, V> data; | |
}; | |
template< | |
template<typename, typename> typename M, | |
typename K, | |
typename V | |
> | |
AnyMap(const M<K, V>&) -> AnyMap<M, K, V>; | |
int main() | |
{ | |
std::map<int, char*> map; | |
std::unordered_map<char, double> um; | |
AnyMap m1{map}; | |
AnyMap m2{um}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment