Ranges defined
In this section, we're going to explore what ranges are and examine concrete definitions of the different types of ranges recognized by Phobos. First, we'll dig into an example of the sort of problem ranges are intended to solve and, in the process, develop our own solution. This will help form an understanding of ranges from the ground up.
The problem
As part of an ongoing project, you've been asked to create a utility function, filterArray
, that takes an array of any type and produces a new array containing all of the elements from the source array that satisfy a Boolean condition. The algorithm should be nondestructive, meaning it should not modify the source array at all. For example, given an array of integers as the input, filterArray
could be used to produce a new array containing all of the even numbers from the source array.
It should be immediately obvious that a function template can handle the requirement to support any type. With a bit of thought and experimentation...