#include <iostream>
#include <vector>
#include <typeinfo>
//std::vector<int> getContainer()
auto getContainer() -> std::vector<int>//C++11, trailing return type syntax
//auto getContainer()//C++14
{
std::vector<int> c = {1, 2, 3, 4};
return c;
}
int main(int argc, char *argv[])
{
auto i = 10;
std::cout<<typeid(i).name()<<std::endl;
auto d = 3.14;
std::cout<<typeid(d).name()<<std::endl;
auto c = getContainer();
std::cout<<typeid(c).name()<<std::endl;
for(int i = 0; i < c.size(); i++)
std::cout<<c[i]<<" ";
std::cout<<std::endl;
return 0;
}
//g++ main.cpp -std=c++14
#include <iostream>
#include <initializer_list>
#include <typeinfo>
template <class T, class T2>
auto getProduct(T a, T2 b) -> decltype(a*b)//C++11, trailing return type syntax
auto getProduct(T a, T2 b)//C++14
{
auto p = a*b;
std::cout<<"Type: "<<typeid(p).name()<<std::endl;
return p;
}
int main(int argc, char *argv[])
{
int a = 1;
double b = 10.0;
std::cout<<getProduct(1, 4)<<std::endl;
return 0;
}