#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
using namespace std;
template <typename T, size_t sizet>
size_t size_t_fnof(T (&array)[sizet]);
#define setting_size_t(z) z,size_t_fnof(z)
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define element_of_array 10
#define array_and_sizet int array[], size_t sizet
int find_max_fn(array_and_sizet);
int find_max_element_fn(array_and_sizet);
/*
template<size_t sizet>
int find_max_fn_using_with_std__array(array<int,sizet>array);
template<size_t sizet>
int find_max_element_fn_using_with_std__array(array<int,sizet>array);
*/
#define nameoftemplate template<size_t sizet>
#define fnnameofarray(type,name,array) type name(array<int,sizet>array)
#define templatefnarray(type,name,array) nameoftemplate fnnameofarray(type,name,array)
/*
nameoftemplate
fnnameofarray(int,find_max_fn_using_with_std__array,array);
nameoftemplate
fnnameofarray(int,find_max_element_fn_using_with_std__array,array);
*/
templatefnarray(int,find_max_fn_using_with_std__array,array);
templatefnarray(int,find_max_element_fn_using_with_std__array,array);
/*
template<typename T, typename A>//allocator generic template
int find_max_fn_using_with_vector(vector<T,A>myvector);
*/
int find_max_fn_using_with_vector(vector<int>myvector);
int find_max_element_fn_using_with_vector(vector<int>myvector);
int main(int argc, char** argv) {
// const size_t element_of_array = 10;
int myarray[element_of_array];
auto value = 0;
array<int,element_of_array>array;
vector<int>myvector(element_of_array);
auto scan = [&value](int& variable)->void
{
variable = value++;
return;
};
auto print = [](const int& variable)->void
{
cout<<variable<<endl;
return;
};
cout<<"List all elements in the array"<<endl;
for(int k=0;k<element_of_array;k++)myarray[k] = k;
for(int k=0;k<element_of_array;k++)cout<<myarray[k]<<endl;
cout<<"find max using with max function: "<<find_max_fn(setting_size_t(myarray))<<endl;
cout<<"find max using with max_element function: "<<find_max_element_fn(setting_size_t(myarray))<<endl;
/*
for(auto it = array.begin(); it != array.end(); ++it)*it = value++;
for(auto it = array.begin(); it != array.end(); ++it)cout<<*it<<endl;
*/
/*
for_each(array.begin(),array.end(),scan); //set
for_each(array.begin(),array.end(),print); //get
cout<<"find max using with max function: "<<find_max_fn_using_with_std__array(array)<<"(std::array)"<<endl;
cout<<"find max using with max_element function: "<<find_max_element_fn_using_with_std__array(array)<<"(std::array)"<<endl;
*/
/*
for(vector<int>::iterator it = myvector.begin(); it != myvector.end(); ++it)*it = value++;
for(vector<int>::iterator it = myvector.begin(); it != myvector.end(); ++it)cout<<*it<<endl;
cout<<"find max using with max function: "<<find_max_fn_using_with_vector(myvector)<<"(vector)"<<endl;
cout<<"find max using with max_element function: "<<find_max_element_fn_using_with_vector(myvector)<<"(vector)"<<endl;
*/
system("pause");
return 0;
}
template <typename T, size_t sizet>
size_t size_t_fnof(T (&array)[sizet])
{
return sizet;
}
int find_max_fn(array_and_sizet)
{
int largest;
int range = sizet - 1;
for(int k=0;k<range;k++)
if(k==0)
{
largest = max(array[k],array[k+1]);
}
else
{
largest = max(largest,array[k+1]);
}
return largest;
}
int find_max_element_fn(array_and_sizet)
{
int largest;
largest = *max_element(array,array+sizet);
return largest;
}
templatefnarray(int,find_max_fn_using_with_std__array,array)
{
int largest;
int range = sizet - 1;
for(int k=0;k<range;k++)
if(k==0)
{
largest = max(array[k],array[k+1]);
}
else
{
largest = max(largest,array[k+1]);
}
return largest;
}
templatefnarray(int,find_max_element_fn_using_with_std__array,array)
{
int largest;
/*largest = *max_element(array,array+sizet);*/
largest = *max_element(array.begin(),array.end());
return largest;
}
int find_max_fn_using_with_vector(vector<int>myvector)
{
int largest;
size_t sizet = myvector.size();
int range = sizet - 1;
for(int k=0;k<range;k++)
if(k==0)
{
largest = max(myvector[k],myvector[k+1]);
}
else
{
largest = max(largest,myvector[k+1]);
}
return largest;
}
int find_max_element_fn_using_with_vector(vector<int>myvector)
{
int largest;
/*largest = *max_element(array,array+sizet);*/
largest = *max_element(myvector.begin(),myvector.end());
return largest;
}