1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
//-----------------------------------------------------------------------------
/** @file libboardgame_base/Range.h
@author Markus Enzenberger
@copyright GNU General Public License version 3 or later */
//-----------------------------------------------------------------------------
#ifndef LIBBOARDGAME_BASE_RANGE_H
#define LIBBOARDGAME_BASE_RANGE_H
#include <cstddef>
namespace libboardgame_base {
//-----------------------------------------------------------------------------
template<typename T>
class Range
{
public:
Range() = default;
Range(T* begin, T* end)
: m_begin(begin),
m_end(end)
{ }
T* begin() const { return m_begin; }
T* end() const { return m_end; }
size_t size() const { return m_end - m_begin; }
bool empty() const { return m_begin == m_end; }
bool contains(T& t) const;
private:
T* m_begin;
T* m_end;
};
template<typename T>
bool Range<T>::contains(T& t) const
{
for (auto& i : *this)
if (i == t)
return true;
return false;
}
//-----------------------------------------------------------------------------
} // namespace libboardgame_base
#endif // LIBBOARDGAME_BASE_RANGE_H
|