title: C++ pairs and pointers
body: <p>I don't know what can I do to make this work in C++.</p>
  
  <p>The intend is:</p>
  
  <pre><code>pair&lt;int, int&gt; foo() {
    if(cond) {
      return std::make_pair(1,2);
    }
    return NULL; //error: no viable conversion from 'long' to 'pair&lt;int, int&gt;
  }
  void boo() {
    pair&lt;int, int&gt; p = foo();
    if (p == NULL) { //error: comparison between NULL and non-pointer ('int, int' and NULL)
      // doA
    } else {
      int a = p.first;
      int b = p.second;
      // doB
    }
  }
  </code></pre>
  
  <p>Since I cannot use return NULL in C++, here is my 2nd try:</p>
  
  <pre><code>pair&lt;int, int&gt;* foo() {
    if(cond) {
      return &amp;std::make_pair(1,2); //error: returning address of local temporary object)
    }
    return nullptr;
  }
  void boo() {
    pair&lt;int, int&gt;* p = foo();
    if (p == nullptr) {
      // doA
    } else {
      int a = p-&gt;first;
      int b = p-&gt;second;
      // doB
    }
  }
  </code></pre>
  
  <p>What is the correct way to be able to return a pair and a null value.</p>