I am trying to implement an "emplace" feature in an object. It is structured like below. I have a template object that pairs a size_t to a template type. I would like to be able to construct this in place in a std library container, e.g., a vector. I am not using a std::pair
as my class B
will be offering other functions around the data.
How do I need to modify the code, so that I can invoke emplace like in the main?
#include <iostream>
#include <vector>
using namespace std;
class C {
public:
C(const string& _s) : s(_s) {}
C(string&& _s) : s(_s) {}
private:
string s;
};
template<typename A>
class B {
public:
B(size_t _i, const A& _a) : i(_i), a(_a) {}
B(size_t _i, A&& _a) : i(_i), a(_a) {}
private:
size_t i;
A a;
};
int main() {
vector<B<C>> v;
v.emplace_back(5, "Hello");
}