Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class T,const int N>
- T* createArr(T (*gen)() ){
- T * mas = new T[N];
- for (int i=0; i<N; i++){
- mas[i] = gen();
- }
- return mas;
- }
- //--------------------------
- template<class T>
- T gen(){
- return rand()%100;
- }
- int main(){
- const int N = 10;
- int * arr;
- arr = createArr<int, N>(gen);
- return 0;
- }
- //-------------------------------
- template<class T, const int N>
- void map(T* arr, T (*change)(T) ){
- for(int i=0; i<N; i++){
- arr[i] = change(arr[i]);
- }
- }
- template<class T>
- T change(T elem){
- return elem * elem;
- }
- int main(){
- const int N = 5;
- int * arr = new int[N];
- for (int i=0; i<5; i++){
- arr[i] = i;
- }
- map<int, N>(arr, change);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement