#pragma once #include #include #include namespace ext { /// For loop adaptor which is used to iterate through a half-closed interval [begin, end). template inline auto range(BeginType begin, EndType end) { using CommonType = typename std::common_type::type; return boost::counting_range(begin, end); } template inline auto range(Type end) { return range(static_cast(0), end); } /// The same as range(), but every value is casted statically to a specified `ValueType`. /// This is useful to iterate through all constants of a enum. template inline auto range_with_static_cast(BeginType begin, EndType end) { using CommonType = typename std::common_type::type; if constexpr (std::is_same_v) return boost::counting_range(begin, end); else return boost::counting_range(begin, end) | boost::adaptors::transformed([](CommonType x) -> ValueType { return static_cast(x); }); } template inline auto range_with_static_cast(EndType end) { return range_with_static_cast(static_cast(0), end); } }