/** @file sortedvector.h * @brief a binary search std::vector * @author Paolo Medici [ medici AT ce DOT unipr DOT it ] **/ template<class T> class sortedvector: public std::vector<T> { typedef typename std::vector<T> _parent; typedef typename _parent::iterator iterator; public: void sort() { std::sort(_parent::begin(), _parent::end()); } iterator find(T val) { int a = 0, b = _parent::size() - 1; T *v = &(*_parent::begin()); while(a<=b) { int p = (a + b) / 2; if(val == v[p]) return iterator (v + p); else if(val < v[p]) b = p - 1; else a = p + 1; }; return _parent::end(); } };