Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
gsl_utils.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
10#include <gsl/gsl>
11
12namespace momentum {
13
25template <typename T>
26[[nodiscard]] std::span<T> cast_span(std::span<std::byte> bs) {
27 auto ptr = reinterpret_cast<T*>(bs.data());
28 auto tsize = gsl::narrow<decltype(bs)::size_type>(sizeof(T));
29 return {ptr, bs.size_bytes() / tsize};
30}
31
43template <typename T>
44[[nodiscard]] std::span<const T> cast_span(std::span<const std::byte> bs) {
45 auto ptr = reinterpret_cast<const T*>(bs.data());
46 auto tsize = gsl::narrow<decltype(bs)::size_type>(sizeof(T));
47 return {ptr, bs.size_bytes() / tsize};
48}
49
50} // namespace momentum
std::span< T > cast_span(std::span< std::byte > bs)
Casts a span of bytes to a span of a different type.
Definition gsl_utils.h:26