Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualÁlvaro

Posted 25 December 2012 - 01:55 PM

I agree to avoid switch in most situations. I often write things like this:
#include <unordered_map>

int Foo(int value) {
  static std::unordered_map<int, int> const map = {{0,1}, {1,4}, {2,2}};

  auto it = map.find(value);
  return it == map.end() ? 100 : it->second;
}

#3Álvaro

Posted 25 December 2012 - 01:54 PM

I agree to avoid switch in most situations. I often write things like this:
#include <unordered_map>

int Foo(int value) {
  static std::unordered_map<int, int> map = {{0,1}, {1,4}, {2,2}};

  auto it = map.find(value);
  return it == map.end() ? 100 : it->second;
}

#2Álvaro

Posted 25 December 2012 - 01:53 PM

I agree to avoid switch in most situations. I often write things like this:

#include <unordered_map>
</p><div> </div>
<div>int Foo(int value) {</div>
<div>  static std::unordered_map<int, int> map = {{0,1}, {1,4}, {2,2}};</div>
<div> </div>
<div>  auto it = map.find(value);</div>
<div>  return it == map.end() ? 100 : it->second;</div>
<div>}</div>
<div>
 

#1Álvaro

Posted 25 December 2012 - 01:53 PM

I agree to avoid switch in most situations. I often write things like this:

#include <unordered_map>
</p><div> </div>
<div>int Foo(int value) {</div>
<div>  static std::unordered_map<int, int> map = {{0,1}, {1,4}, {2,2}};</div>
<div> </div>
<div>  auto it = map.find(value);</div>
<div>  return it == map.end() ? 100 : it->second;</div>
<div>}</div>
<div>
<div>#include <unordered_map></div>
<div> </div>
<div>int Foo(int value) {</div>
<div>  static std::unordered_map<int, int> map = {{0,1}, {1,4}, {2,2}};</div>
<div> </div>
<div>  auto it = map.find(value);</div>
<div>  return it == map.end() ? 100 : it->second;</div>
<div>}</div>
<div>
 

PARTNERS