I have a C ++ class that contains a member std::list. Now I want to add a method that can be used to insert the values ββof another container into this list. Something like that:
template<class factType>
class BeliefSet
{
std::list<factType> m_List;
void SetFacts(??? IterBegin, ??? IterEnd)
{
m_List.insert(m_List.end(), IterBegin, IterEnd);
}
};
Now my question is: what do I need to replace ???, so that it can take an iterator of any (or at least the most common) containers std, such as list, vectoretc ...? I tried it with help std::iterator<std::input_iterator_tag, factType>, but that didn't work.
Note that this should also work with the copy constructor, for example:
const std::list<factType>& GetFacts() const
{
return m_List;
}
explicit BeliefSet(const BeliefSet& Other)
{
auto facts = Other.GetFacts();
SetFacts(facts.begin(), facts.end());
}
source
share