// Exam.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include template auto print_type_info(const T&t) { if constexpr(std::is_integral::value) { return t * t; } else if constexpr(std::is_floating_point::value) { return t + t; } else { return t; } } void test_constexpr() { std::cout << print_type_info(3) << "\n"; std::cout << print_type_info(2.1) << "\n"; std::cout << print_type_info("string") << "\n"; } void test_condtion_init_statement() { const std::string example = "Tere tulemast siia"; if (const auto to_find = example.find("siia"); to_find != std::string::npos) { std::cout << "String olemas" << "\n"; } if (const auto to_find = example.find("Teres"); to_find != std::string::npos) { std::cout << "Antud lause sisaldab stringi 'Tere'"<< "\n"; } else { std::cout << "Antud lause ei sisalda stringi 'Tere'" << "\n"; } } template auto average(T ... t) { return (t + ...) / sizeof ...(t); } void test_fold_expr() { std::cout << average(1, 2, 3.5, 4.1) << "\n"; } using Paar = std::pair; Paar get_test_pair() { return Paar{ "tere", 2 }; } void test_structured_binding() { int a[2] = { 2, 1 }; auto[x, y] = a; std::cout << x << "\n"; std::cout << y << "\n"; auto[x2, y2] = get_test_pair(); std::cout << x2 << "\n"; std::cout << y2 << "\n"; } int multiply(int i){ return i * i; } void test_invoke() { std::cout << std::invoke(multiply, 5) << "\n"; } int main() { test_constexpr(); test_condtion_init_statement(); test_fold_expr(); test_structured_binding(); test_invoke(); return 0; }