COIN-OR::LEMON - Graph Library

Ticket #325: stl-iterators-maps-2463647b2411.patch

File stl-iterators-maps-2463647b2411.patch, 4.0 KB (added by Gábor Gévay, 7 years ago)
  • contrib/stlit_test/stlit_test.cc

    # HG changeset patch
    # User Gabor Gevay <ggab90@gmail.com>
    # Date 1390059398 -3600
    #      Sat Jan 18 16:36:38 2014 +0100
    # Node ID 2463647b2411f53666b2182090dcca27a32c7da8
    # Parent  79271f3a7b98e3797fdd852d73f9637a01b4092c
    STL style iterators for maps.
    
    diff --git a/contrib/stlit_test/stlit_test.cc b/contrib/stlit_test/stlit_test.cc
    a b  
    1010#include <lemon/bfs.h>
    1111#include <lemon/bellman_ford.h>
    1212#include <lemon/euler.h>
     13#include <lemon/maps.h>
    1314
    1415
    1516using namespace std;
     
    167168//    auto a = t.begin();
    168169//  }
    169170
     171  cout<<endl;
    170172
     173  {
     174    SmartDigraph g;
     175    auto u=g.addNode(), v=g.addNode();
     176    g.addArc(u,v);  g.addArc(v,u);
     177    IterableBoolMap<SmartDigraph, SmartDigraph::Node> m1(g);
     178    for(auto v: m1.items(0))
     179      cout<<g.id(v)<<endl;
     180    for(auto v: m1.falseKeys())
     181      cout<<g.id(v)<<endl;
     182    for(auto v: m1.trueKeys())
     183      cout<<g.id(v)<<endl;
     184    IterableIntMap<SmartDigraph, SmartDigraph::Node> m2(g);
     185    for(auto v: m2.items(0))
     186      cout<<g.id(v)<<endl;
     187    IterableValueMap<SmartDigraph, SmartDigraph::Node, double> m3(g);
     188    for(auto v: m3.items(0.2))
     189      cout<<g.id(v)<<endl;
     190  }
    171191
    172192  return 0;
    173193}
  • lemon/maps.h

    diff --git a/lemon/maps.h b/lemon/maps.h
    a b  
    2525#include <map>
    2626
    2727#include <lemon/core.h>
     28#include <lemon/bits/stl_iterators.h>
    2829
    2930///\file
    3031///\ingroup maps
     
    25812582      const IterableBoolMap* _map;
    25822583    };
    25832584
     2585    /// \brief STL style iterator for the keys mapped to \c true.
     2586    ///
     2587    /// This is an STL style wrapper for \ref TrueIt.
     2588    /// It can be used in range-based for loops, stl algorithms, etc.
     2589    LemonRangeWrapper1<TrueIt, IterableBoolMap>
     2590    trueKeys() {
     2591      return LemonRangeWrapper1<TrueIt, IterableBoolMap>(*this);
     2592    }
     2593
     2594
    25842595    /// \brief Iterator for the keys mapped to \c false.
    25852596    ///
    25862597    /// Iterator for the keys mapped to \c false. It works
     
    26202631      const IterableBoolMap* _map;
    26212632    };
    26222633
     2634    /// \brief STL style iterator for the keys mapped to \c false.
     2635    ///
     2636    /// This is an STL style wrapper for \ref FalseIt.
     2637    /// It can be used in range-based for loops, stl algorithms, etc.
     2638    LemonRangeWrapper1<FalseIt, IterableBoolMap>
     2639    falseKeys() {
     2640      return LemonRangeWrapper1<FalseIt, IterableBoolMap>(*this);
     2641    }
     2642
     2643
    26232644    /// \brief Iterator for the keys mapped to a given value.
    26242645    ///
    26252646    /// Iterator for the keys mapped to a given value. It works
     
    26642685      const IterableBoolMap* _map;
    26652686    };
    26662687
     2688    /// \brief STL style iterator for the keys mapped to a given value.
     2689    ///
     2690    /// This is an STL style wrapper for \ref ItemIt.
     2691    /// It can be used in range-based for loops, stl algorithms, etc.
     2692    LemonRangeWrapper2<ItemIt, IterableBoolMap, bool>
     2693    items(bool value) {
     2694      return LemonRangeWrapper2<ItemIt, IterableBoolMap, bool>(*this, value);
     2695    }
     2696
    26672697  protected:
    26682698
    26692699    virtual void add(const Key& key) {
     
    30053035      const IterableIntMap* _map;
    30063036    };
    30073037
     3038    /// \brief STL style iterator for the keys with the same value.
     3039    ///
     3040    /// This is an STL style wrapper for \ref ItemIt.
     3041    /// It can be used in range-based for loops, stl algorithms, etc.
     3042    LemonRangeWrapper2<ItemIt, IterableIntMap, int>
     3043    items(int value) {
     3044      return LemonRangeWrapper2<ItemIt, IterableIntMap, int>(*this, value);
     3045    }
     3046
     3047
    30083048  protected:
    30093049
    30103050    virtual void erase(const Key& key) {
     
    32483288      const IterableValueMap* _map;
    32493289    };
    32503290
     3291    /// \brief STL style iterator for the keys with the same value.
     3292    ///
     3293    /// This is an STL style wrapper for \ref ItemIt.
     3294    /// It can be used in range-based for loops, stl algorithms, etc.
     3295    LemonRangeWrapper2<ItemIt, IterableValueMap, V>
     3296    items(const V& value) {
     3297      return LemonRangeWrapper2<ItemIt, IterableValueMap, V>(*this, value);
     3298    }
     3299
     3300
    32513301  protected:
    32523302
    32533303    virtual void add(const Key& key) {