feat: add initializer list
This commit is contained in:
parent
ea201fe0f9
commit
5a3798a604
4 changed files with 34 additions and 3 deletions
|
@ -20,7 +20,7 @@ configure_file("${PROJECT_SOURCE_DIR}/include/version.h.in"
|
||||||
"${PROJECT_BINARY_DIR}/include/version.h")
|
"${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)
|
src/ifswitch.cpp src/initlist.cpp)
|
||||||
|
|
||||||
target_compile_features(hello PUBLIC cxx_std_20)
|
target_compile_features(hello PUBLIC cxx_std_20)
|
||||||
|
|
||||||
|
|
5
include/initlist.h
Normal file
5
include/initlist.h
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace initlist {
|
||||||
|
void test();
|
||||||
|
};
|
22
src/initlist.cpp
Normal file
22
src/initlist.cpp
Normal 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;
|
||||||
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "version.h"
|
|
||||||
|
|
||||||
#include "constexp.h"
|
#include "constexp.h"
|
||||||
#include "ifswitch.h"
|
#include "ifswitch.h"
|
||||||
|
#include "initlist.h"
|
||||||
#include "null.h"
|
#include "null.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
@ -23,6 +23,10 @@ int main(int argc, char **argv) {
|
||||||
<< "Ifswitch test:" << std::endl;
|
<< "Ifswitch test:" << std::endl;
|
||||||
ifswitch::test();
|
ifswitch::test();
|
||||||
|
|
||||||
|
std::cout << "\n"
|
||||||
|
<< "Initializer list test:" << std::endl;
|
||||||
|
initlist::test();
|
||||||
|
|
||||||
std::cout << "\nExiting" << std::endl;
|
std::cout << "\nExiting" << std::endl;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
Loading…
Reference in a new issue