feat: add if/switch
This commit is contained in:
parent
b3a7b6fb2b
commit
90f78aa9ea
4 changed files with 39 additions and 1 deletions
|
@ -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
7
include/ifswitch.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
namespace ifswitch {
|
||||
|
||||
void test();
|
||||
|
||||
};
|
25
src/ifswitch.cpp
Normal file
25
src/ifswitch.cpp
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue