The only obvious reason to use a pointer here is if you want to be able to dynamically create new domino sets at runtime, say by calling a function. For that, using a smart pointer is the way to go. For example:
#include <iostream>
#include <memory>
#include <vector>
#include <map>
std::unique_ptr<std::vector<std::pair<int,int>>> dominoFactory() {
//note syntax with make_unique
std::unique_ptr<std::vector<std::pair<int,int>>> vec =
std::make_unique<std::vector<std::pair<int,int>>>();
//make a pair object to serve as a loader for the vector
std::pair<int,int> temp;
for (int i = 6; i >= 0; i--) {
for (int j = 0; j <= i; j++) {
temp = std::make_pair(i, j);
vec->push_back(temp);
}
}
return vec;
}
int main() {
//transfer ownership to a unique_ptr in the calling function:
std::unique_ptr<std::vector<std::pair<int,int>>> pieces = dominoFactory();
//dereference the pointer to access the vector internals
for (auto x : *pieces) {
//use pair methods to display each value
std::cout << x.first << " : " << x.second << std::endl;
}
return 0;
}
This approach should be robust against memory leaks and is much preferable to using new.