I seem to have the following problem. I have a class BSK
(Binary Knapsack) which contains a struct Item
in which an identifier
can be std::string
or int
. Then I have a vector<Items> itemlist_
and I need to insert a new Item in the beginning. I am trying to do something like this and it works for int
but does not work for string
. Thank you!
template <class T>
class BKS final
{
public:
struct Item
{
T identifier;
int weight;
int benefit;
};
// some methods ...
}
I am trying to do something like this and it works for int
but does not work for string
. Thank you!
if(std::is_same<T, int>::value){
Item toInsert = {0,0,0};
itemlist_.insert(itemlist_.begin(), toInsert);
else{
Item toInsert = {"aa", 0, 0};
itemlist_.insert(itemlist_.begin(), toInsert);
}