diff --git a/chapters/chapter_02/CMakeLists.txt b/chapters/chapter_02/CMakeLists.txt index ae0ff82..2bc50d2 100644 --- a/chapters/chapter_02/CMakeLists.txt +++ b/chapters/chapter_02/CMakeLists.txt @@ -1,5 +1,6 @@ -add_library(chapter_02 src/initlist.cpp src/null.cpp src/constexp.cpp - src/ifswitch.cpp src/structured_binding.cpp) +add_library( + 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) diff --git a/chapters/chapter_02/include/type_inference.h b/chapters/chapter_02/include/type_inference.h new file mode 100644 index 0000000..d6a7df6 --- /dev/null +++ b/chapters/chapter_02/include/type_inference.h @@ -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"; } +}; diff --git a/chapters/chapter_02/src/type_inference.cpp b/chapters/chapter_02/src/type_inference.cpp new file mode 100644 index 0000000..75b9db5 --- /dev/null +++ b/chapters/chapter_02/src/type_inference.cpp @@ -0,0 +1,14 @@ +#include "type_inference.h" +#include +#include + +void TypeInferenceTest::run() { + + const std::vector 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; +} diff --git a/src/main.cpp b/src/main.cpp index 51eeb4b..94d49ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include "initlist.h" #include "null.h" #include "structured_binding.h" +#include "type_inference.h" #include "version.h" int main(int argc, char **argv) { @@ -22,6 +23,7 @@ int main(int argc, char **argv) { chapter_2_tests.emplace_back(std::make_unique()); chapter_2_tests.emplace_back(std::make_unique()); chapter_2_tests.emplace_back(std::make_unique()); + chapter_2_tests.emplace_back(std::make_unique()); for (auto &test : chapter_2_tests) { std::cout << "\n" << test->name() << ":" << std::endl;