all_of

June 9, 2019 ยท View on GitHub

Description : This function operates on whole range of array elements and checks for a given property on every element and returns true when each element in range satisfies specified property, else returns false.

Example :

int main() { 

	std::vector<int> v{10, 2, 4, 6}; 
	
	if (std::all_of(v.begin(), v.end(), [](int i){ return i % 2 == 0; })) { 
		std::cout << "All numbers are even\n"; 
	} 
    else{
        std::cout << "All numbers are not even\n"; 
    }
}

Run Code