feat: add structured binding test
This commit is contained in:
parent
88742436a1
commit
543b4b832a
4 changed files with 36 additions and 11 deletions
|
@ -1,5 +1,5 @@
|
||||||
add_library(chapter_02 src/initlist.cpp src/null.cpp src/constexp.cpp
|
add_library(chapter_02 src/initlist.cpp src/null.cpp src/constexp.cpp
|
||||||
src/ifswitch.cpp)
|
src/ifswitch.cpp src/structured_binding.cpp)
|
||||||
|
|
||||||
target_compile_features(chapter_02 PUBLIC cxx_std_20)
|
target_compile_features(chapter_02 PUBLIC cxx_std_20)
|
||||||
|
|
||||||
|
|
8
chapters/chapter_02/include/structured_binding.h
Normal file
8
chapters/chapter_02/include/structured_binding.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "chapter_interface.h"
|
||||||
|
|
||||||
|
class StructuredBindingTest : public ChapterTest {
|
||||||
|
public:
|
||||||
|
virtual void run() override;
|
||||||
|
};
|
12
chapters/chapter_02/src/structured_binding.cpp
Normal file
12
chapters/chapter_02/src/structured_binding.cpp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#include "structured_binding.h"
|
||||||
|
#include <cstdint>
|
||||||
|
#include <iostream>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
std::tuple<const char *, uint32_t> func() { return {"32", 32}; }
|
||||||
|
|
||||||
|
void StructuredBindingTest::run() {
|
||||||
|
const auto &[str, val] = func();
|
||||||
|
|
||||||
|
std::cout << "Bound values: " << str << " and " << val << std::endl;
|
||||||
|
}
|
25
src/main.cpp
25
src/main.cpp
|
@ -1,13 +1,13 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "constexp.h"
|
#include "constexp.h"
|
||||||
#include "ifswitch.h"
|
#include "ifswitch.h"
|
||||||
#include "initlist.h"
|
#include "initlist.h"
|
||||||
#include "null.h"
|
#include "null.h"
|
||||||
|
#include "structured_binding.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
@ -15,16 +15,21 @@ int main(int argc, char **argv) {
|
||||||
std::cout << "Running " << PROJECT_NAME << ", version " << VERSION << "\n"
|
std::cout << "Running " << PROJECT_NAME << ", version " << VERSION << "\n"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
std::vector<std::tuple<std::string, std::unique_ptr<ChapterTest>>>
|
std::vector<std::tuple<const char *, std::unique_ptr<ChapterTest>>>
|
||||||
chapterTests;
|
chapter_2_tests;
|
||||||
chapterTests.emplace_back("Null test", std::make_unique<NullTest>());
|
|
||||||
chapterTests.emplace_back("If/Switch test", std::make_unique<IfswitchTest>());
|
|
||||||
chapterTests.emplace_back("Constexpr test", std::make_unique<ConstExpTest>());
|
|
||||||
chapterTests.emplace_back("Initializer list test",
|
|
||||||
std::make_unique<InitListTest>());
|
|
||||||
|
|
||||||
for (auto &[name, test] : chapterTests) {
|
chapter_2_tests.emplace_back("Nullptr test", std::make_unique<NullTest>());
|
||||||
std::cout << "\n" << name << std::endl;
|
chapter_2_tests.emplace_back("If/Switch test",
|
||||||
|
std::make_unique<IfswitchTest>());
|
||||||
|
chapter_2_tests.emplace_back("Constexpr test",
|
||||||
|
std::make_unique<ConstExpTest>());
|
||||||
|
chapter_2_tests.emplace_back("Initializer list test",
|
||||||
|
std::make_unique<InitListTest>());
|
||||||
|
chapter_2_tests.emplace_back("Structured binding test",
|
||||||
|
std::make_unique<StructuredBindingTest>());
|
||||||
|
|
||||||
|
for (auto &[test_description, test] : chapter_2_tests) {
|
||||||
|
std::cout << "\n" << test_description << ":" << std::endl;
|
||||||
test->run();
|
test->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue