feat: add enum class test
This commit is contained in:
parent
9dbfc54b76
commit
16d75fe48c
4 changed files with 36 additions and 1 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
23
chapters/chapter_02/src/enum.cpp
Normal file
23
chapters/chapter_02/src/enum.cpp
Normal 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;
|
||||
}
|
9
chapters/chapter_02/src/enum.h
Normal file
9
chapters/chapter_02/src/enum.h
Normal 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"; }
|
||||
};
|
Loading…
Reference in a new issue