Skip to content

Commit 0c1af30

Browse files
jeongseok-metameta-codesync[bot]
authored andcommitted
Migrate from gsl::span to std::span (C++20) (#758)
Summary: Pull Request resolved: #758 Now that C++20 is the default standard, migrate from `gsl::span` to `std::span` throughout the codebase to use the standard library implementation instead of the Guidelines Support Library (GSL). Changes: - Replaced `gsl::span<T>` with `std::span<T>` in headers and source files - Replaced `gsl::make_span()` with direct `std::span` construction - Replaced `gsl::as_bytes()` with `std::as_bytes()` - Updated `#include <gsl/gsl>` to `#include <span>` - Updated code style documentation to reference `std::span` - Kept `DeduceSpanType<T>` utility (required for template argument deduction with nested templates) - Kept `gsl::narrow` and `gsl::narrow_cast` utilities (no C++20 standard replacement available) Reviewed By: cstollmeta Differential Revision: D85808123 fbshipit-source-id: 1bf09f19e30eb6ed448a4df7a65cfcae15d1f217
1 parent 8e1dbcf commit 0c1af30

File tree

91 files changed

+386
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+386
-370
lines changed

momentum/character/blend_shape.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include "momentum/common/checks.h"
1111

12+
#include <gsl/narrow>
13+
1214
namespace momentum {
1315

1416
template <typename T>
@@ -37,7 +39,7 @@ void BlendShape::computeShape(
3739
}
3840

3941
VectorXf BlendShape::estimateCoefficients(
40-
gsl::span<const Vector3f> vertices,
42+
std::span<const Vector3f> vertices,
4143
const float regularization,
4244
const VectorXf& weights) const {
4345
MT_CHECK(
@@ -86,12 +88,12 @@ VectorXf BlendShape::estimateCoefficients(
8688
}
8789
}
8890

89-
BlendShape::BlendShape(gsl::span<const Vector3f> baseShape, const size_t numShapes)
91+
BlendShape::BlendShape(std::span<const Vector3f> baseShape, const size_t numShapes)
9092
: BlendShapeBase(baseShape.size(), numShapes),
9193
baseShape_(baseShape.begin(), baseShape.end()),
9294
factorizationValid_(false) {}
9395

94-
void BlendShape::setShapeVector(const size_t index, gsl::span<const Vector3f> shape) {
96+
void BlendShape::setShapeVector(const size_t index, std::span<const Vector3f> shape) {
9597
BlendShapeBase::setShapeVector(index, shape);
9698

9799
// mark as not up to date

momentum/character/blend_shape.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ struct BlendShape : public BlendShapeBase {
2222

2323
/// @param baseShape Base shape vertices
2424
/// @param numShapes Number of blend shapes
25-
BlendShape(gsl::span<const Vector3f> baseShape, size_t numShapes);
25+
BlendShape(std::span<const Vector3f> baseShape, size_t numShapes);
2626

27-
void setBaseShape(gsl::span<const Vector3f> baseShape) {
27+
void setBaseShape(std::span<const Vector3f> baseShape) {
2828
baseShape_.assign(baseShape.begin(), baseShape.end());
2929
}
3030

@@ -67,15 +67,15 @@ struct BlendShape : public BlendShapeBase {
6767
/// @param weights Optional per-vertex importance weights
6868
/// @return Estimated blend shape coefficients
6969
[[nodiscard]] VectorXf estimateCoefficients(
70-
gsl::span<const Vector3f> vertices,
70+
std::span<const Vector3f> vertices,
7171
float regularization = 1.0f,
7272
const VectorXf& weights = VectorXf()) const;
7373

7474
/// Overrides base method to also invalidate factorization
7575
///
7676
/// @param index Index of the shape vector to set
7777
/// @param shapeVector Vector of vertex offsets
78-
void setShapeVector(size_t index, gsl::span<const Vector3f> shapeVector);
78+
void setShapeVector(size_t index, std::span<const Vector3f> shapeVector);
7979

8080
/// Compares all components of two blend shapes
8181
///

momentum/character/blend_shape_base.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include "momentum/common/checks.h"
1111

12+
#include <gsl/narrow>
13+
1214
namespace momentum {
1315

1416
template <typename T>
@@ -33,7 +35,7 @@ void BlendShapeBase::applyDeltas(
3335
BlendShapeBase::BlendShapeBase(const size_t modelSize, const size_t numShapes)
3436
: shapeVectors_(MatrixXf::Zero(modelSize * 3, numShapes)) {}
3537

36-
void BlendShapeBase::setShapeVector(const size_t index, gsl::span<const Vector3f> shape) {
38+
void BlendShapeBase::setShapeVector(const size_t index, std::span<const Vector3f> shape) {
3739
MT_CHECK(modelSize() == shape.size(), "{} is not {}", modelSize(), shape.size());
3840
MT_CHECK(
3941
gsl::narrow<Eigen::Index>(shape.size()) * 3 == shapeVectors_.rows(),

momentum/character/blend_shape_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct BlendShapeBase {
5252

5353
/// @param index Index of the shape vector to set
5454
/// @param shapeVector Vector of vertex offsets
55-
void setShapeVector(size_t index, gsl::span<const Vector3f> shapeVector);
55+
void setShapeVector(size_t index, std::span<const Vector3f> shapeVector);
5656

5757
[[nodiscard]] Eigen::Index shapeSize() const {
5858
return shapeVectors_.cols();

momentum/character/character_utility.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ Character replaceSkeletonHierarchy(
598598
tgtCharacter.blendShape};
599599
}
600600

601-
Character removeJoints(const Character& character, gsl::span<const size_t> jointsToRemove) {
601+
Character removeJoints(const Character& character, std::span<const size_t> jointsToRemove) {
602602
std::vector<bool> toRemove(character.skeleton.joints.size(), false);
603603
for (const auto& j : jointsToRemove) {
604604
MT_THROW_IF(j >= character.skeleton.joints.size(), "Invalid joint found in removeJoints.");

momentum/character/character_utility.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace momentum {
6262
/// specified joints.
6363
[[nodiscard]] Character removeJoints(
6464
const Character& character,
65-
gsl::span<const size_t> jointsToRemove);
65+
std::span<const size_t> jointsToRemove);
6666

6767
/// Maps the input ModelParameter motion to a target character by matching model parameter names.
6868
/// Mismatched names will be discarded (source) or set to zero (target).

momentum/character/linear_skinning.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "momentum/math/mesh.h"
1515

1616
#include <dispenso/parallel_for.h>
17+
#include <gsl/narrow>
1718

1819
namespace momentum {
1920

@@ -246,7 +247,7 @@ Affine3f getInverseSSDTransformation(
246247
void applyInverseSSD(
247248
const TransformationList& inverseBindPose,
248249
const SkinWeights& skin,
249-
gsl::span<const Vector3f> points,
250+
std::span<const Vector3f> points,
250251
const SkeletonState& state,
251252
Mesh& mesh) {
252253
// some sanity checks
@@ -258,7 +259,7 @@ void applyInverseSSD(
258259
std::vector<Vector3f> applyInverseSSD(
259260
const TransformationList& inverseBindPose,
260261
const SkinWeights& skin,
261-
gsl::span<const Vector3f> points,
262+
std::span<const Vector3f> points,
262263
const SkeletonState& state) {
263264
MT_CHECK(
264265
state.jointState.size() == inverseBindPose.size(),

momentum/character/linear_skinning.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Affine3f getInverseSSDTransformation(
116116
std::vector<Vector3f> applyInverseSSD(
117117
const TransformationList& inverseBindPose,
118118
const SkinWeights& skin,
119-
gsl::span<const Vector3f> points,
119+
std::span<const Vector3f> points,
120120
const SkeletonState& state);
121121

122122
/// Applies inverse SSD to points, storing results in a mesh
@@ -132,7 +132,7 @@ std::vector<Vector3f> applyInverseSSD(
132132
void applyInverseSSD(
133133
const TransformationList& inverseBindPose,
134134
const SkinWeights& skin,
135-
gsl::span<const Vector3f> points,
135+
std::span<const Vector3f> points,
136136
const SkeletonState& state,
137137
Mesh& mesh);
138138

momentum/character/parameter_transform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ParameterTransformT<T> ParameterTransformT<T>::empty(size_t nJointParameters) {
4949
}
5050

5151
template <typename T>
52-
ParameterTransformT<T> ParameterTransformT<T>::identity(gsl::span<const std::string> jointNames) {
52+
ParameterTransformT<T> ParameterTransformT<T>::identity(std::span<const std::string> jointNames) {
5353
ParameterTransformT<T> result;
5454
const size_t nJoints = jointNames.size();
5555
const size_t nJointParameters = nJoints * kParametersPerJoint;

momentum/character/parameter_transform.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <momentum/character/types.h>
1212
#include <momentum/math/utility.h>
1313

14-
#include <gsl/span>
14+
#include <span>
1515

1616
#include <string>
1717
#include <unordered_map>
@@ -102,7 +102,7 @@ struct ParameterTransformT {
102102

103103
/// Return a ParameterTransform object where the model parameters are identical to the joint
104104
/// parameters.
105-
[[nodiscard]] static ParameterTransformT<T> identity(gsl::span<const std::string> jointNames);
105+
[[nodiscard]] static ParameterTransformT<T> identity(std::span<const std::string> jointNames);
106106

107107
/// Compute activeJointParams based on the transform and the input ParameterSet.
108108
[[nodiscard]] VectorX<bool> computeActiveJointParams(const ParameterSet& ps = allParams()) const;

0 commit comments

Comments
 (0)