CETL 0.0.0
 
Loading...
Searching...
No Matches
Example 2: CETL span type.

Full example for cetl::pf20::span

#include <iostream>
#include <string>
#include <algorithm>
#include <gtest/gtest.h>
TEST(example_02_span, dynamic_span)
{
std::string greeting{"Hello Dynamic World."};
// Works just like a std::span...
cetl::pf20::span<const char> dynamic{greeting.c_str(), 13};
auto print = [](const char c) { std::cout << c; };
// Print just the characters in the span...
std::for_each(dynamic.begin(), dynamic.end(), print);
// or...
std::string substring{dynamic.begin(), dynamic.size()};
std::cout << substring << std::endl;
}
template<typename T, std::size_t Extent>
{
std::for_each(sp.begin(), sp.end(), [&os](const char c) { os << c; });
return os;
}
TEST(example_02_span, static_span)
{
constexpr const char* greeting = "Hello Static World";
std::cout << cetl::pf20::span<const char, 12>{greeting, 12} << std::endl;
}
A borrowed view into a contiguous set of objects.
Definition span.hpp:55
constexpr iterator begin() const noexcept
Iterator to the first element in the span.
Definition span.hpp:245
constexpr iterator end() const noexcept
Iterator to the address after the last element in the span.
Definition span.hpp:261
T endl(T... args)
T for_each(T... args)
Defines a span type that is mostly compliant to ISO/IEC 14882:2020(E) but compatible with C++14 and n...