1
0
Fork 0

feat: add initializer list

main
mandlm 2023-10-20 14:27:28 +02:00
parent ea201fe0f9
commit 5a3798a604
Signed by: mandlm
GPG Key ID: 4AA25D647AA54CC7
4 changed files with 34 additions and 3 deletions

View File

@ -20,7 +20,7 @@ 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
src/ifswitch.cpp)
src/ifswitch.cpp src/initlist.cpp)
target_compile_features(hello PUBLIC cxx_std_20)

5
include/initlist.h Normal file
View File

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

22
src/initlist.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "initlist.h"
#include <initializer_list>
#include <iostream>
#include <vector>
class InitList {
public:
std::vector<unsigned int> _list;
InitList(std::initializer_list<unsigned int> list) : _list(list) {}
};
void initlist::test() {
InitList initList{1, 2, 3, 4, 5};
std::cout << "InitList: ";
for (const auto &item : initList._list) {
std::cout << item << " ";
}
std::cout << std::endl;
}

View File

@ -1,11 +1,11 @@
#include <cstdlib>
#include <iostream>
#include "version.h"
#include "constexp.h"
#include "ifswitch.h"
#include "initlist.h"
#include "null.h"
#include "version.h"
int main(int argc, char **argv) {
@ -23,6 +23,10 @@ int main(int argc, char **argv) {
<< "Ifswitch test:" << std::endl;
ifswitch::test();
std::cout << "\n"
<< "Initializer list test:" << std::endl;
initlist::test();
std::cout << "\nExiting" << std::endl;
return EXIT_SUCCESS;