feat: test auto keyword

This commit is contained in:
Michael Mandl 2023-10-21 22:45:28 +02:00
parent b78b86742b
commit 9b20fc7126
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
4 changed files with 28 additions and 2 deletions

View file

@ -1,5 +1,6 @@
add_library(chapter_02 src/initlist.cpp src/null.cpp src/constexp.cpp add_library(
src/ifswitch.cpp src/structured_binding.cpp) chapter_02 src/initlist.cpp src/null.cpp src/constexp.cpp src/ifswitch.cpp
src/structured_binding.cpp src/type_inference.cpp)
target_compile_features(chapter_02 PUBLIC cxx_std_20) target_compile_features(chapter_02 PUBLIC cxx_std_20)

View file

@ -0,0 +1,9 @@
#pragma once
#include "chapter_interface.h"
class TypeInferenceTest : public ChapterTest {
public:
virtual void run() override;
virtual const char *name() const override { return "Type inference test"; }
};

View file

@ -0,0 +1,14 @@
#include "type_inference.h"
#include <iostream>
#include <vector>
void TypeInferenceTest::run() {
const std::vector<int> int_vec = {1, 2, 3, 4, 5};
std::cout << "vector iterator with auto: ";
for (auto it = int_vec.cbegin(); it != int_vec.cend(); ++it) {
std::cout << *it << " ";
}
std::cout << std::endl;
}

View file

@ -8,6 +8,7 @@
#include "initlist.h" #include "initlist.h"
#include "null.h" #include "null.h"
#include "structured_binding.h" #include "structured_binding.h"
#include "type_inference.h"
#include "version.h" #include "version.h"
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -22,6 +23,7 @@ int main(int argc, char **argv) {
chapter_2_tests.emplace_back(std::make_unique<ConstExpTest>()); chapter_2_tests.emplace_back(std::make_unique<ConstExpTest>());
chapter_2_tests.emplace_back(std::make_unique<InitListTest>()); chapter_2_tests.emplace_back(std::make_unique<InitListTest>());
chapter_2_tests.emplace_back(std::make_unique<StructuredBindingTest>()); chapter_2_tests.emplace_back(std::make_unique<StructuredBindingTest>());
chapter_2_tests.emplace_back(std::make_unique<TypeInferenceTest>());
for (auto &test : chapter_2_tests) { for (auto &test : chapter_2_tests) {
std::cout << "\n" << test->name() << ":" << std::endl; std::cout << "\n" << test->name() << ":" << std::endl;