0

How can I apply built in function count( ) to the 3D array?

I declared a 3D vector vector<vector<vector<char>>>. If I think of this 3D vector as two 2D vectors divided in two layers (each 2D vector is in its own layer), how can I count number of times an element appears only in that layer using std::count( ) from library algorithm?

18th Apr 2020, 7:14 PM
ja008
ja008 - avatar
1 Réponse
0
If you want to count the total number of times a value appears in a two-dimensional vector, you could use std::count() in combination with std::accumulate(), e.g. std::accumulate ( layer.cbegin(), layer.cend(), 0, [] ( const unsigned int sum, const std::vector< char >& v ) { return ( sum + std::count( v.cbegin(), v.cend(), YourValue ) ); } );
19th Apr 2020, 7:50 AM
Shadow
Shadow - avatar