// file : libbutl/multi-index.mxx -*- C++ -*- // copyright : Copyright (c) 2014-2019 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file #ifndef __cpp_modules_ts #pragma once #endif // C includes. #ifndef __cpp_lib_modules_ts #include // declval() #include // hash #endif // Other includes. #ifdef __cpp_modules_ts export module butl.multi_index; #ifdef __cpp_lib_modules_ts import std.core; #endif #endif #include LIBBUTL_MODEXPORT namespace butl { // Google the "Emulating Boost.MultiIndex with Standard Containers" blog // post for details. // template struct map_key { mutable const T* p; map_key (const T* v = 0): p (v) {} bool operator< (const map_key& x) const {return *p < *x.p;} bool operator== (const map_key& x) const {return *p == *x.p;} }; template struct map_iterator_adapter: I { typedef const typename I::value_type::second_type value_type; typedef value_type* pointer; typedef value_type& reference; map_iterator_adapter () {} map_iterator_adapter (I i): I (i) {} map_iterator_adapter& operator= (I i) {static_cast (*this) = i; return *this;} reference operator* () const {return I::operator* ().second;} pointer operator-> () const {return &I::operator-> ()->second;} }; } LIBBUTL_MODEXPORT namespace std { template struct hash>: hash { size_t operator() (butl::map_key x) const noexcept (noexcept (declval> () (*x.p))) { return hash::operator() (*x.p); } }; }