Skip to content

Commit

Permalink
Switch to type_index for type map
Browse files Browse the repository at this point in the history
  • Loading branch information
barche committed Aug 21, 2023
1 parent e91db4b commit 70bb337
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions include/jlcxx/type_conversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stack>
#include <stdexcept>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <type_traits>
#include <iostream>
Expand Down Expand Up @@ -332,7 +333,7 @@ struct CachedDatatype
};

// Work around the fact that references aren't part of the typeid result
using type_hash_t = std::pair<std::size_t, std::size_t>;
using type_hash_t = std::pair<std::type_index, std::size_t>;

namespace detail
{
Expand All @@ -342,7 +343,7 @@ struct TypeHash
{
static inline type_hash_t value()
{
return std::make_pair(typeid(T).hash_code(), std::size_t(0));
return std::make_pair(std::type_index(typeid(T)), std::size_t(0));
}
};

Expand All @@ -351,7 +352,7 @@ struct TypeHash<T&>
{
static inline type_hash_t value()
{
return std::make_pair(typeid(T).hash_code(), std::size_t(1));
return std::make_pair(std::type_index(typeid(T)), std::size_t(1));
}
};

Expand All @@ -360,7 +361,7 @@ struct TypeHash<const T&>
{
static inline type_hash_t value()
{
return std::make_pair(typeid(T).hash_code(), std::size_t(2));
return std::make_pair(std::type_index(typeid(T)), std::size_t(2));
}
};

Expand Down Expand Up @@ -395,7 +396,7 @@ class JuliaTypeCache
const auto insresult = jlcxx_type_map().insert(std::make_pair(type_hash<SourceT>(), CachedDatatype(dt, protect)));
if(!insresult.second)
{
std::cout << "Warning: Type " << typeid(SourceT).name() << " already had a mapped type set as " << julia_type_name(insresult.first->second.get_dt()) << " using hash " << insresult.first->first.first << " and const-ref indicator " << insresult.first->first.second << std::endl;
std::cout << "Warning: Type " << typeid(SourceT).name() << " already had a mapped type set as " << julia_type_name(insresult.first->second.get_dt()) << " using hash " << insresult.first->first.first.hash_code() << " and const-ref indicator " << insresult.first->first.second << std::endl;
return;
}
}
Expand Down

0 comments on commit 70bb337

Please sign in to comment.