if (it == end() || *val < *(*it))
{
m_container.insert(it, val);
return true;
}
return false;
}
[/code]
Теперь я нашел рабочее решение, в котором функция-член реализована в объявлении класса. Однако я не могу разделить код на декларацию и реализацию. Честно говоря, в этом нет необходимости, но выглядело бы красивее.
Код: Выделить всё
template
bool insert_sorted(const value_type& val)
{
auto it = std::lower_bound(begin(), end(), val, [](const value_type& a, const value_type& b)->bool { return *a < *b; });
if (it == end() || *val < *(*it))
{
m_container.insert(it, val);
return true;
}
return false;
}
Код: Выделить всё
template
bool insert_sorted(const value_type& val);
Код: Выделить всё
template
bool PtrVector::insert_sorted(const value_type& val)
{
auto it = std::lower_bound(begin(), end(), val, [](const value_type& a, const value_type& b)->bool { return *a < *b; });
if (it == end() || *val < *(*it))
{
m_container.insert(it, val);
return true;
}
return false;
}
Спасибо Реми за подчистку текста.
Подробнее здесь: https://stackoverflow.com/questions/793 ... pe-t-where