feat: test auto keyword
This commit is contained in:
parent
b78b86742b
commit
9b20fc7126
@ -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)
|
||||||
|
|
||||||
|
9
chapters/chapter_02/include/type_inference.h
Normal file
9
chapters/chapter_02/include/type_inference.h
Normal 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"; }
|
||||||
|
};
|
14
chapters/chapter_02/src/type_inference.cpp
Normal file
14
chapters/chapter_02/src/type_inference.cpp
Normal 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;
|
||||||
|
}
|
@ -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;
|
||||||
|
Reference in New Issue
Block a user