-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚀 (spikes): Add stl_cxxsupport spike
- Loading branch information
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Leka - LekaOS | ||
# Copyright 2021 APF France handicap | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_mbed_executable(spike_stl_cxxsupport) | ||
|
||
target_include_directories(spike_stl_cxxsupport | ||
PRIVATE | ||
. | ||
) | ||
|
||
target_sources(spike_stl_cxxsupport | ||
PRIVATE | ||
main.cpp | ||
) | ||
|
||
target_link_custom_leka_targets(spike_stl_cxxsupport) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Leka - LekaOS | ||
// Copyright 2021 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <lstd_array> | ||
#include <lstd_span> | ||
|
||
#include "drivers/BufferedSerial.h" | ||
#include "rtos/ThisThread.h" | ||
|
||
#include "HelloWorld.h" | ||
#include "LogKit.h" | ||
|
||
using namespace leka; | ||
using namespace std::chrono; | ||
|
||
void foo(lstd::span<int> span) | ||
{ | ||
log_info("from foo! span size: %i", span.size()); | ||
for (const auto &v: span) { | ||
log_info("v: %i", v); | ||
} | ||
} | ||
|
||
int main(void) | ||
{ | ||
static auto serial = mbed::BufferedSerial(USBTX, USBRX, 115200); | ||
leka::logger::set_print_function([](const char *str, size_t size) { serial.write(str, size); }); | ||
|
||
log_info("Hello, World!\n"); | ||
|
||
rtos::ThisThread::sleep_for(2s); | ||
|
||
auto hello = HelloWorld(); | ||
hello.start(); | ||
|
||
// | ||
// MARK: - lstd::to_array | ||
// | ||
|
||
log_info("Create array with lstd::to_array"); | ||
|
||
auto arr = lstd::to_array({1, 2, 3, 4}); | ||
|
||
for (const auto &v: arr) { | ||
log_info("v: %i", v); | ||
} | ||
|
||
// | ||
// MARK: - lstd::span | ||
// | ||
|
||
log_info("Pass std::array to lstd::span"); | ||
|
||
foo(arr); | ||
|
||
log_info("Create span from array, auto deduce size"); | ||
|
||
auto span0 = lstd::span {arr}; | ||
|
||
for (const auto &v: span0) { | ||
log_info("v: %i", v); | ||
} | ||
|
||
foo(span0); | ||
|
||
log_info("Create span from begin pointer and size"); | ||
|
||
auto span1 = lstd::span {arr.begin(), 3}; | ||
|
||
for (const auto &v: span1) { | ||
log_info("v: %i", v); | ||
} | ||
|
||
foo(span1); | ||
|
||
log_info("Create span from specific i-th element and size - i"); | ||
|
||
auto span2 = lstd::span {arr.begin() + 2, arr.size() - 2}; | ||
|
||
for (const auto &v: span2) { | ||
log_info("v: %i", v); | ||
} | ||
|
||
foo(span2); | ||
|
||
return 1; | ||
} |