Skip to content

Commit 594bd4e

Browse files
authored
Merge pull request #665 from OpenVicProject/force_typed_indices_indexed_flat_map
Force typed indices for IndexedFlatMap
2 parents 4c0b9d4 + e0592cf commit 594bd4e

File tree

3 files changed

+163
-161
lines changed

3 files changed

+163
-161
lines changed

src/openvic-simulation/types/IdentifierRegistry.hpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "openvic-simulation/utility/Concepts.hpp"
99
#include "openvic-simulation/utility/Getters.hpp"
1010
#include "openvic-simulation/utility/Logger.hpp"
11-
#include "openvic-simulation/utility/Concepts.hpp"
1211

1312
namespace OpenVic {
1413
/* Callbacks for trying to add duplicate keys via UniqueKeyRegistry::add_item */
@@ -176,17 +175,6 @@ namespace OpenVic {
176175
using StorageInfo = _StorageInfo<item_type>;
177176
using internal_storage_index_type = typename StorageInfo::index_type;
178177
using identifier_index_map_t = template_string_map_t<internal_storage_index_type, Case>;
179-
180-
//helper to avoid error 'index_t': is not a member of external_value_type
181-
template<typename EXTERNAL_VALUE_TYPE, typename = void>
182-
struct get_index_t {
183-
using type = std::size_t;
184-
};
185-
186-
template<has_index EXTERNAL_VALUE_TYPE>
187-
struct get_index_t<EXTERNAL_VALUE_TYPE, std::void_t<typename EXTERNAL_VALUE_TYPE::index_t>> {
188-
using type = typename EXTERNAL_VALUE_TYPE::index_t;
189-
};
190178

191179
public:
192180
using storage_type = typename StorageInfo::storage_type;
@@ -372,10 +360,7 @@ namespace OpenVic {
372360
return nullptr; \
373361
} \
374362
constexpr external_value_type CONST* get_item_by_index(const index_t typed_index) CONST { \
375-
std::size_t index; \
376-
if constexpr (std::is_same_v<index_t, std::size_t>) { \
377-
index = typed_index; \
378-
} else { index = type_safe::get(typed_index); } \
363+
const std::size_t index = get_index_as_size_t(typed_index); \
379364
if (index < 0 || index >= items.size()) { \
380365
return nullptr; \
381366
} \

0 commit comments

Comments
 (0)