1
0
Fork 0

feat: add if/switch

main
mandlm 2023-10-19 08:32:43 +02:00
parent b3a7b6fb2b
commit 90f78aa9ea
Signed by: mandlm
GPG Key ID: 4AA25D647AA54CC7
4 changed files with 39 additions and 1 deletions

View File

@ -12,7 +12,8 @@ include(ExportCompileCommands)
configure_file("${PROJECT_SOURCE_DIR}/include/version.h.in"
"${PROJECT_BINARY_DIR}/include/version.h")
add_executable(hello src/main.cpp src/null.cpp src/constexp.cpp)
add_executable(hello src/main.cpp src/null.cpp src/constexp.cpp
src/ifswitch.cpp)
target_compile_features(hello PUBLIC cxx_std_20)

7
include/ifswitch.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
namespace ifswitch {
void test();
};

25
src/ifswitch.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>
#include "ifswitch.h"
void ifswitch::test() {
std::vector<uint32_t> vec = {1, 2, 3, 4};
if (auto it = std::find(vec.begin(), vec.end(), 23); it != vec.end()) {
std::cout << "Found element 23 in vector" << std::endl;
} else {
std::cout << "No element 23 in vector" << std::endl;
}
switch (auto it = vec.rbegin(); *it) {
case 4:
std::cout << "Found 4 at the back" << std::endl;
break;
default:
std::cout << "No 4 at the back" << std::endl;
break;
}
}

View File

@ -4,6 +4,7 @@
#include "version.h"
#include "constexp.h"
#include "ifswitch.h"
#include "null.h"
int main(int argc, char **argv) {
@ -18,6 +19,10 @@ int main(int argc, char **argv) {
<< "Constexpr test:" << std::endl;
constexp::test();
std::cout << "\n"
<< "Ifswitch test:" << std::endl;
ifswitch::test();
std::cout << "\nExiting" << std::endl;
return EXIT_SUCCESS;