///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2026 Equinor ASA // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. // // See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #pragma once #include #include template class TypeSafeIndex { public: // Default constructor constexpr TypeSafeIndex() noexcept : m_value( 0 ) { } // Explicit constructor from size_t (prevents implicit conversion) explicit constexpr TypeSafeIndex( size_t value ) noexcept : m_value( value ) { } // Explicit conversion to size_t explicit constexpr operator size_t() const noexcept { return m_value; } // Getter for when you need the value constexpr size_t value() const noexcept { return m_value; } // Comparison operators constexpr bool operator==( const TypeSafeIndex& other ) const noexcept = default; constexpr auto operator<=>( const TypeSafeIndex& other ) const noexcept = default; // Arithmetic operators (if needed) constexpr TypeSafeIndex& operator++() noexcept { ++m_value; return *this; } private: size_t m_value; }; // Hash support for using in std::unordered_map, etc. namespace std { template struct hash> { size_t operator()( const TypeSafeIndex& idx ) const noexcept { return hash{}( idx.value() ); } }; } // namespace std // Define specific types using tag structs struct ReservoirCellIndexTag { }; // Global cell index in the full IJK reservoir grid using ReservoirCellIndex = TypeSafeIndex; struct ActiveCellIndexTag { }; // Index into the subset of active cells. This is usually the index used to access results data. using ActiveCellIndex = TypeSafeIndex;