Wikipedia:Reference desk/Archives/Computing/2016 February 3#more STL questions

{{#ifeq:{{PAGENAME}}|Special:Undelete| |{{#if:|

}} {{#ifeq:{{NAMESPACE}}|Wikipedia|{{#switch:{{NAMESPACE}}|= |
}}|{{error:not substituted|Archive header}}
}}}} {{#if:|
}}
width = "100%"
colspan="3" align="center" | Computing desk
width="20%" align="left" | < February 2

! width="25%" align="center"|<< Jan | February | Mar >>

! width="20%" align="right" |{{#ifexist:Wikipedia:Reference desk/Archives/Computing/2016 February 4|February 4|Current desk}} >

align=center width=95% style="background: #FFFFFF; border: 1px solid #003EBA;" cellpadding="8" cellspacing="0"
style="background: #5D7CBA; text-align: center; font-family:Arial; color:#FFFFFF;" | Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is {{#ifexist:Wikipedia:Reference desk/Archives/Computing/2016 February 13|an archive page|a transcluded archive page}}. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.

__TOC__

= February 3 =

more STL questions

First of all, thank you to everyone who helped me yesterday; I really appreciate it. Now, why doesn't the following code compile?

  1. include
  2. include
  3. include
  4. include

typedef std::vector myvec;

typedef std::unordered_map > > uom;

int f(){

myvec v;

uom S;

v.clear();

v.push_back(3);

v.push_back(-3);

S[v] = 4.4;

return (0);

}

The compiler gives a whole bunch of error messages starting with

Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/unordered_map:386:17: error: no matching function for

call to object of type 'const std::__1::equal_to > >'

{return static_cast(*this)(__x);}

^19:59, 3 February 2016 (UTC)19:59, 3 February 2016 (UTC)19:59, 3 February 2016 (UTC)19:59, 3 February 2016 (UTC)19:59, 3 February 2016 (UTC)19:59, 3 February 2016 (UTC)~

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__hash_table:2014:21: note: in instantiation of member

function 'std::__1::__unordered_map_hasher >, std::__1::__hash_value_type

std::__1::allocator >, double>, std::__1::equal_to > >, true>::operator()' requested here

size_t __hash = hash_function()(__k);

I don't understand these messages, can anyone advise? Thanks, Robinh (talk) 19:59, 3 February 2016 (UTC)

:Don't use Nimur's code; it is wrong (and causing compilation errors) for reasons unrelated to your problem. To use unordered_map, just replace map with unordered_map in your code and provide a hash function for vector<int>. In the previous thread I linked to a couple of possible hash functions and an explanation of how to use custom hash functions with unordered_map. -- BenRG (talk) 03:06, 4 February 2016 (UTC)