# Bosonic sites with itensor 2

+1 vote
edited

Hi guys,

I have a problem of syntax after I moved from Itensor 1 to Itensor 2. I had a piece of code which allows to create a set of sites, some of them spins the others bosons. I cannot construct anymore the bosons sites with a vector of 'IndexQN'. I have the feeling this is related to the new storage type of the library, but I am not sure :)

inline void SpinBoson::
constructSites()
{
std::vector<IndexQN> I;
for(int j = 1; j <= N_; ++j)
{
if (std::binary_search(Is_.begin(),Is_.end(),j))
{
site_.at(j) = IQIndex(nameint("S=1/2 site=",j),
Index(nameint("Up for site",j),1,Site),QN(+1,0),
Index(nameint("Dn for site",j),1,Site),QN(-1,0));
}
else
{
for (int r = 0;r<d_;r++)
{
std::string str = format("%d for site %d",r,j);
I.push_back(IndexQN(Index(str,1,Site),QN(0,r)));
}
site_.at(j) = IQIndex(nameint("boson site=",j),I);
}
}
}


Note, the error is

no matching constructor for initialization of
'itensor::IQIndex'
site_.at(j) = IQIndex(nameint("boson site=",j),I);
^       ~~~~~~~~~~~~~~~~~~~~~~~~~~
itensor2/itensor/iqindex.h:55:5: note: candidate constructor not viable: no known conversion from
'std::vector<IndexQN>' to 'storage &&' (aka 'vector<itensor::IndexQN> &&') for 2nd argument


Hi, thanks for the question.

At a glance, the line

site_.at(j) = IQIndex(nameint("boson site=",j),I);


seems to be what's causing the problem. I think all you need to do to fix it is change the line to

site_.at(j) = IQIndex(nameint("boson site=",j),std::move(I));


The 2.0 version of this constructor still accepts a vector but for efficiency reasons requires it to be "moved" into the IQIndex to avoid making a copy. Be aware that afterward the vector I will be empty.

Please give it a try and let me know if it works or not!