Я использую iterator_facade для обеспечения поддержки итератора для класса. Однако, поскольку iterator_facade :: dereference возвращается по ссылке, и это объект с возвращаемой нетривиальной копией-константой, моя производительность страдает от каждой разыменования (как профилируется VTune) в результате постоянного выполнения этих копии. Есть ли способ обойти это?Ускорение boost :: iterator_facade dereference
class time_series::iterator : public boost::iterator_facade<
time_series::iterator,
time_series::variable_vec,
boost::bidirectional_traversal_tag,
timestep> //<--- dereference type
{
public:
iterator();
iterator(const iterator& src);
~iterator();
iterator& operator=(const iterator& rhs);
private:
//the following satisfies the reqs for a boost::facade bidirectional iterator
friend class boost::iterator_core_access;
friend class time_series;
const timestep& dereference() const;
bool equal(iterator const& other) const;
void increment();
void decrement();
std::ptrdiff_t distance_to(iterator const& other) const;
//iterators for the current step
timestep _currentStep;// <--returned on dereference, is non-trivial to copy.
};
редактировать: согласно комментарию
const timestep& time_series::iterator::dereference() const
{
return _currentStep;
}
Можете ли вы предоставить код для 'dereference()', 'increment()' и 'decment()'? –