Task Specialization with method
Method declearation inside class.
The same method can be specialized like this: Here, this method only execute when the template is Gossip_Girl. otherwise the above method is executed.
Methods body should be decleared outside the class. General function should be given with the template used in class like this:
typename Vector<T>::const_iterator Vector<T>::begin_z() const {
if (sz == 0) return end();
return const_iterator{values};
}
template<>
Vector<Gossip_Girl>::const_iterator Vector<Gossip_Girl>::begin_z() const
{
if (sz == 0) return end_z();
int lastIndexofBrooklyn = -1;
for(size_t i = 0; i < sz; i++) {
std::string area = to_string((values+i)->get_area());
if(area.find("Brooklyn") != std::string::npos) {
lastIndexofBrooklyn = i;
}
}
if(lastIndexofBrooklyn == -1) return end_z();
return const_iterator{values+lastIndexofBrooklyn};
}
Comments
Post a Comment