comparing two hashes (maps)

Discussion in 'C++' started by mahurshi@gmail.com, Nov 12, 2005.

  1. Guest

    i have two hashes (maps)

    map <int, int> FAULTFREENETS;
    map <int, int> FAULTNETS;

    is there a way i can check if FAULTFREENETS = FAULTNETS with just one
    statement instead of writing a for loop with iterators, etc. ?

    (just trying to reduce code clutter)
     
    , Nov 12, 2005
    #1
    1. Advertising

  2. wrote:
    > i have two hashes (maps)
    >
    > map <int, int> FAULTFREENETS;
    > map <int, int> FAULTNETS;
    >
    > is there a way i can check if FAULTFREENETS = FAULTNETS with just one


    Don't use all-caps for variable names. Reserve that for macros.

    > statement instead of writing a for loop with iterators, etc. ?
    >
    > (just trying to reduce code clutter)


    Lookup std::equal() from <algorithm> or roll-up your own function and
    call it.


    Jonathan
     
    Jonathan Mcdougall, Nov 12, 2005
    #2
    1. Advertising

  3. wrote:
    > i have two hashes (maps)
    >
    > map <int, int> FAULTFREENETS;
    > map <int, int> FAULTNETS;
    >
    > is there a way i can check if FAULTFREENETS = FAULTNETS with just one
    > statement instead of writing a for loop with iterators, etc. ?
    >
    > (just trying to reduce code clutter)
    >


    Of course, the obvious works

    if (FAULTFREENETS == FAULTNETS)
    {
    cout << "they're equal\n";
    }

    john
     
    John Harrison, Nov 12, 2005
    #3
  4. John Harrison wrote:
    > wrote:
    > > i have two hashes (maps)
    > >
    > > map <int, int> FAULTFREENETS;
    > > map <int, int> FAULTNETS;
    > >
    > > is there a way i can check if FAULTFREENETS = FAULTNETS with just one
    > > statement instead of writing a for loop with iterators, etc. ?
    > >
    > > (just trying to reduce code clutter)
    > >

    >
    > Of course, the obvious works
    >
    > if (FAULTFREENETS == FAULTNETS)
    > {
    > cout << "they're equal\n";
    > }


    I just hate when this happens.


    Jonathan
     
    Jonathan Mcdougall, Nov 12, 2005
    #4
  5. Guest

    perfectamundo. "=" works like a charm.
     
    , Nov 12, 2005
    #5
  6. wrote:
    > i have two hashes (maps)
    >
    > map <int, int> FAULTFREENETS;
    > map <int, int> FAULTNETS;


    If this is std::map, then just use operator ==. But they are not hash maps.

    --

    Valentin Samko - http://www.valentinsamko.com
     
    Valentin Samko, Nov 12, 2005
    #6
  7. wrote:
    > perfectamundo. "=" works like a charm.


    That should be ==, not =.


    Jonathan
     
    Jonathan Mcdougall, Nov 12, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Holness

    Hashes of Hashes via subs

    Ben Holness, Oct 5, 2003, in forum: Perl
    Replies:
    8
    Views:
    579
    Ben Holness
    Oct 8, 2003
  2. Simon Elliott
    Replies:
    4
    Views:
    1,174
    Simon Elliott
    Mar 10, 2005
  3. Marcus
    Replies:
    2
    Views:
    598
    Marcus
    Dec 9, 2005
  4. Steven Arnold

    using hashes as keys in hashes

    Steven Arnold, Nov 23, 2005, in forum: Ruby
    Replies:
    3
    Views:
    175
    Mauricio Fernández
    Nov 23, 2005
  5. Tim O'Donovan

    Hash of hashes, of hashes, of arrays of hashes

    Tim O'Donovan, Oct 27, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    223
Loading...

Share This Page