Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

tuple_map< ... >

Introduction

tuple_map provides a std::map like container for boost's tuple<> template

In addition it allows there to be multiple indexes on the stored tuple. These can be:

There can only be only one set of Composite keys, but combinations of unique and multi-valued or composite and multivalued are possible.
All keys that are unique or part of the composite key must come before the multi-value keys in the tuple declaration.

Inserted keys are Now properly orderd on insert. That is if 2 keys are equal then the all the keys are compared in tuple order to determine the insert position.

Declaration

maps::tuple_map< TupleType, TotalKeys, CompUniqueKeys > map;

Example - Composite Keys

#include <string>
  #include <iostream>
  #include "imp/tuple_map.hpp"

  int main()
  {
    using namespace ::boost::tuples;
    using imp::containers::tuple_map;

    typedef tuple<int, int, std::string> data_t;

    // tupel_map<> with 2 composite int keys and a non-indexed string.
    // the negative value -2 specefies composite keys.
    typedef tuple_map<data_t, 2, -2> tuplemap_t;

    tuplemap_t map;
    //data_t data;

    int inserted =
      map.insert(make_tuple(0, 0, "0 - 0")) +
      map.insert(make_tuple(0, 1, "0 - 1")) +
      map.insert(make_tuple(1, 0, "1 - 0")) +
      map.insert(make_tuple(1, 1, "1 - 1"))
    ;

    std::cout << "inserted " << inserted << " records" << std::endl;

     inserted =
      map.insert(make_tuple(0, 0, "0 - 0")) + // duplicate
      map.insert(make_tuple(2, 1, "2 - 1"))   // ok
    ;

    std::cout << "inserted " << inserted << " records" << std::endl;

    tuplemap_t::iterator< 0 > ptr0 = map.begin<0>(), end0 = map.end<0>();

    for (; ptr0 != end0; ++ptr0)
    {
      std::cout << "0: ("
         << ptr0->get<0>() << "," << ptr0->get<1>() << ") = " << ptr0->get<2>()
         << std::endl
      ;
    }

    tuplemap_t::iterator< 1 > ptr1 = map.begin<1>(), end1 = map.end<1>();
    for (; ptr1 != end1; ++ptr1)
    {
      std::cout << "1: ("
         << ptr1->get<0>() << "," << ptr1->get<1>() << ") = " << ptr1->get<2>()
         << std::endl
      ;
    }
  }
  

[Home]
Generated on Tue Aug 5 04:06:09 2003 for tuple_map by doxygen 1.3-rc3