### EduardoBrito's blog

By EduardoBrito, history, 2 years ago,

Hello everyone!

I want to offer you a blog about the STL of C++11, a few weeks ago I was reading interesting information about this topic in GeeksforGeeks, and today I decided to share this information through this blog for all those interested. In advance, I want to thank all those who pay attention and interest to this blog, and thank any comments about it (positive or negative). Well, let's start now.

I will start with some array algorithms in the C++11 STL, which I did not know before and that can have a very interesting use, depending on the problem.

Array algorithms: these algorithms operate on an array and are useful in saving time during coding and hence useful in competitive programming as well.

all_of(): this function operates on whole range of array elements and can save time to run a loop to check each element one by on. It checks for a given property on every element and returns true when each element in range satisfies specified property, else returns false.

Code

any_of(): this function checks for a given range if there’s even one element satisfying a given property mentioned in function. Returns true if at least one element satisfies the property, else returns false.

Code

none_of(): this function returns true if none of element satisfies the given condition, else returns false.

Code

iota(): this function is used to assign continuous values to array.

Code

accumulate(): this function returns the sum of all the values lying in a range between [first, last) with the variable sum.

Code

Thank you to all

• +49

 » 2 years ago, # |   0 is it applicable for c++14???????
•  » » 2 years ago, # ^ |   0 Yes, it is.
 » 2 years ago, # |   +2 Thanks for share! I have a question the time complexity of those functions is linear?
•  » » 2 years ago, # ^ |   +3 all_of, any_of, none_of, accumulate, iota — O(n)copy_n — O(cnt)
 » 4 months ago, # |   0 what does the following do?ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
•  » » 4 months ago, # ^ |   0 https://stackoverflow.com/questions/31162367/significance-of-ios-basesync-with-stdiofalse-cin-tienullYou can look in the above link
 » 4 months ago, # | ← Rev. 5 →   0 I tried implementing them in python and here are the codes except for none_of but you can do it using all() and not keywords. all_ofdef main(): arr = [1,2,3,4] ans = all([i & 1 for i in arr]) if ans: print("All numbers are odd") else: print("All numbers are not odd")  any_offdef main(): arr = [1,2,3,4] ans = any([i & 1 for i in arr]) if ans: print("There exists a odd number") else: print("No odd number exists")  copy_ndef main(): arr = [1,2,3,4] arr1 = arr.copy() print(arr1) # [1,2,3,4]  iotadef main(): n=10 arr = list(range(1, n + 1)) print(arr) # [1,2,3,4,5,6,7,8,9,10]  accumulatedef main(): import itertools import operator arr=[1,2,3,4,5] result = list(itertools.accumulate(arr, operator.mul)) # [1,2,6,24,120] More Operators — Link