How do I initialize a const std::pair?

Maciek picture Maciek · Aug 5, 2009 · Viewed 33.2k times · Source

Let's say that I've got a :

#include <utility>
using namespace std;
typedef pair<int, int> my_pair;

how do I initialize a const my_pair ?

Answer

anon picture anon · Aug 5, 2009

Use its constructor:

const my_pair p( 1, 2 );