Files
Cpp-in-Embedded-Systems/Chapter10/lambdas/app/src/main_lambda_basics.cpp
Amar Mahmutbegovic 8ce616c0c9 add Chapter10
2024-09-09 20:55:25 +02:00

49 lines
865 B
C++

#include <cstdint>
#include <cstdio>
#include <stm32f072xb.h>
#include <hal.hpp>
#include <uart_stm32.hpp>
#include <retarget.hpp>
#include <algorithm>
#include <array>
int main()
{
hal::init();
hal::uart_stm32 uart(USART2);
uart.init();
retarget::set_stdio_uart(&uart);
std::array<int, 4> arr{5, 3, 4, 1};
const auto print_arr = [&arr](const char* message) {
printf("%s\r\n", message);
for(auto elem : arr) {
printf("%d, ", elem);
}
printf("\r\n");
};
print_arr("Unsorted array:");
std::sort(arr.begin(), arr.end(), [](int a, int b) {
return a < b;});
print_arr("Sorted in ascending order:");
std::sort(arr.begin(), arr.end(), [](int a, int b) {
return a > b;});
print_arr("Sorted in descending order:");
while(true)
{
}
}