PrevUpHomeNext

utx::iota


utx::iota

utx::iota

utx::iota is used to generate auto incremental values to a range.

Different with std::iota: utx::iota can take the range name as its parameter, without begin/end.

Different with std::ranges::iota: utx::iota accepts floating point and some more data types, not limited by std::iter_difference_t.

utx::iota: Range Algorithm

utx::iota

template <
	std::input_or_output_iterator first_type,
	std::sentinel_for<first_type> last_type,
	typename init_value_type,
	utx::same_as<utx::remove_cvref_t<decltype(*(std::declval<first_type>()))>>
		value_type = utx::remove_cvref_t<decltype(*(std::declval<first_type>()))>
>
requires
	std::constructible_from<value_type, const init_value_type &>
		&&
	std::indirectly_writable<first_type, const value_type &>
		&&
	std::movable<value_type>
		&&
	requires (value_type v1, value_type v2)
	{
		{++v1} -> utx::same_as<value_type &>;
		{v1++};
		// std::iter_difference_t is not required.
	}
constexpr first_type iota(first_type first, last_type last, const init_value_type & init);

utx::iota

template <
	std::ranges::range range_type,
	typename init_value_type,
	utx::same_as<utx::remove_cvref_t<std::ranges::borrowed_iterator_t<range_type>>>
		first_type = utx::remove_cvref_t<std::ranges::borrowed_iterator_t<range_type>>,
	utx::same_as<utx::remove_cvref_t<decltype(*(std::declval<first_type>()))>>
		value_type = utx::remove_cvref_t<decltype(*(std::declval<first_type>()))>
>
requires
	std::constructible_from<value_type, const init_value_type>
		&&
	std::ranges::output_range<range_type, const value_type &>
		&&
	std::indirectly_writable<first_type, const value_type &>
		&&
	requires (value_type v1, value_type v2)
	{
		{++v1} -> utx::same_as<value_type &>;
		{v2++};
		// std::iter_difference_t is not required.
	}
constexpr first_type iota(range_type && range, const init_value_type & init);

Header

#include <utxcpp/algorithm.hpp>

c++ example

#include <utxcpp/algorithm.hpp>
#include <utxcpp/core.hpp>

int main()
{
	std::vector<utx::ix32> v1(11);

	utx::iota(v1, -5);
	utx::print(v1);
// -5 -4 -3 -2 -1 0 1 2 3 4 5

	std::vector<utx::fx32> v2(4);

	utx::iota(v2.begin(), v2.end(), 1.4f);
	utx::print(v2);
// 1.400000 2.400000 3.400000 4.400000
}

See Also

utx::ix32

utx::fx32


PrevUpHomeNext

c++ project: Utxcpp   utx::print