feat: add enum class test

This commit is contained in:
Michael Mandl 2023-11-19 15:00:39 +01:00
parent 9dbfc54b76
commit 16d75fe48c
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
4 changed files with 36 additions and 1 deletions

View file

@ -11,7 +11,8 @@ add_library(
src/type_inference.cpp
src/variadic_templates.cpp
src/delegate_constructor.cpp
src/inheritance_constructor.cpp)
src/inheritance_constructor.cpp
src/enum.cpp)
target_compile_features(chapter_02 PUBLIC cxx_std_20)

View file

@ -1,6 +1,7 @@
#include "chapter_2_tests.h"
#include "constexp.h"
#include "delegate_constructor.h"
#include "enum.h"
#include "if_constexpr.h"
#include "ifswitch.h"
#include "inheritance_constructor.h"
@ -25,6 +26,7 @@ std::vector<std::unique_ptr<ChapterTest>> chapter_2_tests() {
chapter_2_tests.emplace_back(std::make_unique<VariadicTemplates>());
chapter_2_tests.emplace_back(std::make_unique<DelegateConstructor>());
chapter_2_tests.emplace_back(std::make_unique<InheritanceConstructor>());
chapter_2_tests.emplace_back(std::make_unique<EnumTest>());
return chapter_2_tests;
}

View file

@ -0,0 +1,23 @@
#include "enum.h"
#include <iostream>
#include <ostream>
enum class MyEnum : unsigned int {
Variant_1 = 23,
Variant_2 = 42,
Variant_3 = Variant_2,
};
std::ostream &operator<<(std::ostream &os, const MyEnum &myEnum) {
os << static_cast<std::underlying_type<MyEnum>::type>(myEnum);
return os;
}
void EnumTest::run() {
auto myEnum_1 = MyEnum::Variant_1;
std::cout << "myEnum_1 is " << myEnum_1 << std::endl;
auto myEnum_2 = MyEnum::Variant_2;
std::cout << "myEnum_2 is " << myEnum_2 << std::endl;
}

View file

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