8 #ifndef BLACKCAT_TENSORS_UTILITY_TYPEMAP_H_     9 #define BLACKCAT_TENSORS_UTILITY_TYPEMAP_H_    11 #include <unordered_map>    21 template<
char... Chars>
    28 template<
char C, 
char... Chars>
    30     static std::string 
name() {
    35 template<
class Key, 
class Value>
    62     using any_ptr = std::shared_ptr<void>;
    63     std::unordered_map<std::size_t, any_ptr> m_any_map;
    65     template<
class K, 
class V>
    72     template<
class K, 
class V>
    74         return m_any_map.find(hash(key)) != m_any_map.end();
    77     template<
class K, 
class V>
    79         static auto deleter = [](
void* data) {
    80             delete reinterpret_cast<V*
>(data);
    84             void* data = 
reinterpret_cast<void*
>(
new V());
    85             m_any_map[hash(key)] = any_ptr(data, deleter);
    88         return *
reinterpret_cast<V*
>(m_any_map[hash(key)].get());
    91     template<
class K, 
class V>
    93         return this->operator[](key);
    97     template<
class K, 
class V, 
class... DefaultArgs>
   102             return m_any_map[hash(key)];
   106     template<
class K, 
class V>
   108         if (!contains(key)) {
   109             return m_any_map[hash(key)] = value;
   111             return m_any_map[hash(key)];
   115     template<
class K, 
class V, 
class... Args>
   117         auto result = m_any_map.emplace(hash(key), args...);
   118         return std::pair<K&, bool> { *(result.first), result.second };
   121     int empty()
 const  { 
return (
int)m_any_map.empty(); }
   122     int size()
  const  { 
return (
int)m_any_map.size(); }
   123     int max_size()
 const { 
return (
int)m_any_map.size(); }
   125     auto begin()
 const { 
return m_any_map.begin(); }
   126     auto end()
 const { 
return m_any_map.end(); }
   128     auto begin() { 
return m_any_map.begin(); }
   129     auto end() { 
return m_any_map.end(); }
   130     auto cbegin() { 
return m_any_map.cbegin(); }
   131     auto cend() { 
return m_any_map.cend(); }
 auto & at(Any_Key< K, V > key)
Definition: any_map.h:92
bool contains(Any_Key< K, V > key) const
Definition: any_map.h:73
Definition: type_traits.h:220
int size() const
Definition: any_map.h:122
auto cend()
Definition: any_map.h:131
int max_size() const
Definition: any_map.h:123
auto emplace(Any_Key< K, V > key, Args &&... args)
Definition: any_map.h:116
int empty() const
Definition: any_map.h:121
auto end() const
Definition: any_map.h:126
V value_type
Definition: any_map.h:38
auto end()
Definition: any_map.h:129
int size_t
Definition: common.h:283
static std::string name()
Definition: any_map.h:30
K key_type
Definition: any_map.h:37
std::string name()
Definition: any_map.h:23
Any_Map stores a buck of std::shared_ptr<void>. 
Definition: any_map.h:60
auto begin()
Definition: any_map.h:128
auto begin() const
Definition: any_map.h:125
auto cbegin()
Definition: any_map.h:130
The Evaluator determines if an expression needs to be greedily optimized. 
Definition: algorithms.h:22