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
12
namespace
momentum
{
13
25
template
<
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
43
template
<
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
momentum
Definition
aligned.h:15
momentum::cast_span
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
io
common
gsl_utils.h
Generated on
for Momentum by
1.15.0