Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for inclusion of Boost.MultiIndex #2

Closed
joaquintides opened this issue Feb 27, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@joaquintides
Copy link

commented Feb 27, 2019

I'd very much like to see Boost.MultiIndex included in this benchmark. As it happens, the library provides a set-like interface rather than that of a map, but the latter can easily be emulated as follows:

#pragma once

#include "Hash.h"
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/member.hpp>
#include <utility>

static const char* MapName = "boost::multi_index::hashed_unique";

template <class T1, class T2>
struct MapElement
{
    using first_type = T1;
    using second_type = T2;
    
    template<class Q1>
    MapElement(Q1&& first):
        first{std::forward<Q1>(first)},
        second{}
        {}

    template<class Q1, class Q2>
    MapElement(Q1&& first, Q2&& second):
        first{std::forward<Q1>(first)},
        second{std::forward<Q2>(second)}
        {}
    
    T1         first;
    mutable T2 second;
};

template <class Key, class Val>
using MapBase = boost::multi_index_container<
    MapElement<Key, Val>,
    boost::multi_index::indexed_by<
        boost::multi_index::hashed_unique<
            boost::multi_index::member<
                MapElement<Key, Val>, Key, &MapElement<Key, Val>::first
            >,
            Hash<Key>
        >
    >
>;

template <class Key, class Val>
struct Map: MapBase<Key, Val>
{
  using super = MapBase<Key, Val>;
  using super::super;
  
  template <class K>
  Val& operator[](K&& key){
      return this->emplace(std::forward<K>(key)).first->second; 
  }
};

@martinus martinus self-assigned this Mar 1, 2019

@martinus martinus added the enhancement label Mar 1, 2019

@martinus

This comment has been minimized.

Copy link
Owner

commented Mar 1, 2019

Thanks for this! I've added it to the benchmark in comit f97c368

@martinus martinus closed this Mar 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.