dxx-rebirth/common/main/d_crange.h
Kp 078a9affa0 Make MAX_SIDES_PER_SEGMENT an iterable range
Iterating over it returns each side number in turn.  This allows
converting many loops of the form:

```
	for (int i = 0; i < MAX_SIDES_PER_SEGMENT; ++i)
```

to the compact form:

```
	for (const auto i : MAX_SIDES_PER_SEGMENT)
```

The compact form brings the usual benefit of range-based for: delegating
iteration to the compiler prevents the loop body from skipping a step,
and makes clear in the code that this is the case.
2022-01-09 15:25:42 +00:00

22 lines
802 B
C++

/*
* This file is part of the DXX-Rebirth project <http://www.dxx-rebirth.com/>.
* It is copyright by its individual contributors, as recorded in the
* project's Git history. See COPYING.txt at the top level for license
* terms and a link to the Git history.
*/
#pragma once
#include "d_range.h"
template <typename index_type, index_type begin_value, index_type end_value>
struct constant_xrange : xrange<index_type, std::integral_constant<index_type, begin_value>, std::integral_constant<index_type, end_value>>
{
using base_type = xrange<index_type, std::integral_constant<index_type, begin_value>, std::integral_constant<index_type, end_value>>;
using base_type::end_type::value;
using base_type::end_type::operator index_type;
constexpr constant_xrange() :
base_type({}, {})
{
}
};