1
0
Fork 0

feat: test decltype

main
mandlm 2023-10-22 12:29:10 +02:00
parent f2bdaae4bf
commit bcc4720b80
Signed by: mandlm
GPG Key ID: 4AA25D647AA54CC7
1 changed files with 32 additions and 0 deletions

View File

@ -1,7 +1,31 @@
#include "type_inference.h"
#include <iostream>
#include <type_traits>
#include <vector>
auto print_sum(auto x, auto y) {
decltype(x + y) sum = x + y;
std::cout << "sum is " << sum << std::endl;
return sum;
}
void print_decltype(auto var) {
std::cout << "variable with value " << var << " is of type ";
if (std::is_same<decltype(var), int>::value) {
std::cout << "int";
} else if (std::is_same<decltype(var), double>::value) {
std::cout << "double";
} else {
std::cout << "unknown";
}
std::cout << std::endl;
}
void TypeInferenceTest::run() {
const std::vector<int> int_vec = {1, 2, 3, 4, 5};
@ -11,4 +35,12 @@ void TypeInferenceTest::run() {
std::cout << *it << " ";
}
std::cout << std::endl;
auto result_1 = print_sum(10.2, 13.3);
print_decltype(result_1);
auto result_2 = print_sum(10, 13);
print_decltype(result_2);
print_decltype("23");
}