Skip to content
Why is a raven like a writing desk?

Thoughts both confusing and enlightening.

Why is a raven like a writing desk?

Thoughts both confusing and enlightening.

VS2010 woes: tuples as map keys

elbeno, 20 February, 201530 June, 2015

Another day, another compiler/library bug. If you’re unfortunate enough to still be using Visual Studio 2010, don’t use tuples as map keys.

#include 
#include 
#include 

using namespace std;

typedef tuple FooT;
typedef map MapT;

int main(int, char*[])
{
  MapT m;

  // put a value in the map
  {
    FooT f(nullptr, 0);
    m[f] = 1337;
  }

  // retrieve a value
  int s;
  {
    FooT f(nullptr, 0);
    auto i = m.find(f);
    if (i != m.end())
    {
      // VS2010 says:
      // error C2440: 'initializing' : 
      // cannot convert from 'const FooT' to 'int *'
      s = i->second;
    }
  }

  return 0;
}
C++ Programming

Post navigation

Previous post
Next post

Related Posts

C++23’s new function syntax

5 September, 20225 September, 2022

We’ve had a couple of ways to spell functions for a long time: And we’ve had a shortcut for that second one for a while, too: (Aside: notice where [[nodiscard]] is positioned, since C++23’s P2173, to apply to the lambda’s call operator.) All these ways to spell functions look the…

Read More

after an hour's fiddling…

29 September, 200529 July, 2007

Got GTK+/gtkmm projects compiling under Win32. Eclipse (CDT) doesn’t really know about pkg-config. So in order to get CDT to drive the command line correctly I had to put the `pkg-config –libs gtkmm-2.4` as part of a -l directive to the linker. It doesn’t work as just a link option…

Read More

C++ Reflection: Another Monad

4 March, 20264 March, 2026

“Discovery consists of seeing what everybody has seen, and thinking what nobody has thought.” — Albert Szent-Györgi, 1937 Nobel Laureate for Medicine I’m sure others have thought this, but they’re certainly not saying much about it. Barry’s recent blog post “Behold the power of meta::substitute” got so close to saying…

Read More

Comment

  1. Alan says:
    20 February, 2015 at 12:11 pm

    Something odd… if i replace

    m[f] = 1337;
    

    with either

    m.insert(std::make_pair(FooT(nullptr, 0), 1337));
    

    or

    m.insert(std::make_pair(f, 1337));
    

    It works fine (compiles and behaves like it should at runtime), even though the error reported by VS when it doesnt work points at the s assignment line!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

©2026 Why is a raven like a writing desk? | WordPress Theme by SuperbThemes