aboutsummaryrefslogtreecommitdiff
path: root/build/key-set
blob: 8c197b8ab6474f9d7fcd9f093b27aa009b644e11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// file      : build/key-set -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#ifndef BUILD_KEY_SET
#define BUILD_KEY_SET

namespace build
{
  // Google the "Emulating Boost.MultiIndex with Standard Containers" blog
  // post for deatils.
  //

  template <typename T>
  struct set_key
  {
    mutable const T* p;

    set_key (const T* v = 0): p (v) {}
    bool operator< (const set_key& x) const {return *p < *x.p;}
  };

  template <typename I>
  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<I&> (*this) = i; return *this;}

    reference operator* () const {return I::operator* ().second;}
    pointer operator-> () const {return &I::operator-> ()->second;}
  };
}

#endif // BUILD_KEY_SET