Range Constructor
Description
There are three types of construction methods:
- (Default) Construct a range instance whose upper and lower bounds are nullptr.
- Construct a range instance by specifying the upper and lower bounds.
- Construct a range instance with the same upper and lower bounds by passing only one pointer of any type.
Prototype
Range() // Default constructor. Both the upper and lower bounds are null pointers.
Range(T *min, T* max) : min_(min), max_(max) // The upper bound (max) and lower bound (min) are specified by users.
Range(T *same_ele) : min_(same_ele), max_(same_ele) // Both the upper and lower bounds are same_ele.
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
min |
Input |
Pointer to the lower bound, of the T* type. |
max |
Input |
Pointer to the upper bound, of the T* type. |
same_ele |
Input |
Used to construct a range instance with the same upper and lower bounds. The values of the upper and lower bounds are assigned by same_ele and are of the T* type. |
Returns
Constructed range object
Restrictions
None
Example
// 1. Construct a range with default configuration. Range<int> range1; // Both the upper and lower bounds are nullptr. // 2. Construct a range with user-defined upper and lower bounds. int min = 0; int max = 1024; Range<int> range2(&min, &max); // The upper bound is 1024 and the lower bound is 0. // 3. Construct a range with the same upper and lower bounds. Range<int> range3(&min); // Both the upper and lower bounds are 0.
Parent topic: Range