Fix compilation error for case when we use std::unordered_map inside map_type for g++ or Mac. Fix should work for C++17. For example: bootstrap::standard_library::map_type<std::unordered_map<std::string, int>>("StringInt_Map")

This commit is contained in:
Oleg Sh 2021-04-10 15:41:27 +02:00
parent 2e77b9d0bf
commit 0469526276

View File

@ -37,6 +37,15 @@ namespace chaiscript
{
namespace standard_library
{
template <class T>
struct isUnorderedMap {
static constexpr bool value = false;
};
template<class Key,class Value>
struct isUnorderedMap<std::unordered_map<Key,Value>> {
static constexpr bool value = true;
};
/// Bidir_Range, based on the D concept of ranges.
/// \todo Update the Range code to base its capabilities on
@ -71,8 +80,15 @@ namespace chaiscript
{
throw std::range_error("Range empty");
}
if constexpr (!isUnorderedMap<typename std::decay<Container>::type>::value)
{
--m_end;
}
else
{
throw std::range_error("Cannot call pop_back for unordered_map");
}
}
decltype(auto) front() const
{
@ -90,7 +106,14 @@ namespace chaiscript
throw std::range_error("Range empty");
}
auto pos = m_end;
if constexpr (!isUnorderedMap<typename std::decay<Container>::type>::value)
{
--pos;
}
else
{
throw std::range_error("Cannot call back for unordered_map");
}
return (*(pos));
}