Example Code From Presentations
Loading...
Searching...
No Matches
std_span_test.cpp File Reference

Example code from the "std::span in C++" presentation. More...

#include <span>
#include <array>
#include <vector>
#include <string>
#include "catch2/catch_test_macros.hpp"
Include dependency graph for std_span_test.cpp:

Functions

template<typename T , std::size_t SZ>
constexpr bool is_dyn_ext (std::span< T, SZ > sp)
 
constexpr int sum3 (std::span< int, 3 > sp)
 
 TEST_CASE ("Spans with both dynamic and static extents", "[basic_usage]")
 
 TEST_CASE ("Calling sum3, ensuring 3 contiguous elements", "[sum3]")
 
template<int N>
consteval int factorial ()
 
 TEST_CASE ("Compile time evaluated factorial function", "[factorial]")
 

Detailed Description

Example code from the "std::span in C++" presentation.

This presentation gives an overview of the std::span class template in the C++ library. It is meant to be for both C++ programmers as well as non C++ programmers to give a short intro to the static compile time capabilities of the C++ language.

std::span with it's non-type template parameter Extent shows a capability not present in many languages - the ability to specify info that is present only at compile time, and does not cost runtime space or time.

Author
Cliff Green

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt)