I have
using namespace std; // for convenience in SO question only
vector<pair<array<int,3>, int>> foo;
and want to emplace_back
an element with pair::first
holding {i,j,k}
and pair::second
holding q
. The only way I could get this compiling was with the rather clumsy
foo.emplace_back(piecewise_construct,
forward_as_tuple(i,j,k),
forward_as_tuple(q));
Is this efficient (i.e. is it guaranteed that the tuple
s will be optimised away)? Or is there another way that is guaranteed efficient?
(I tried
foo.emplace_back(std::initializer_list<int>{i,j,k}, q);
but to no avail with gcc 4.8.1). I know that I can avoid this problem by defining
struct element : std::pair<std::array<int,3>,int>
{
element(int i, int j, int k, int q)
{ first={i,j,k}; second=q; }
};
vector<element> foo;
foo.emplace_back(i,j,k,q);
but I'd prefer to do without such extra code.