SuperDex Physics C++ API
Loading...
Searching...
No Matches
concepts.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19// PLEASE DO NOT ADD OTHER INCLUDES HERE. This header is included in the mochi_physics public API.
21
22#if MOCHI_LANGUAGE_CPP20
23#include <concepts>
24#endif // MOCHI_LANGUAGE_CPP20
25#include <type_traits>
26
27namespace superdex {
28
29namespace details {
30template <typename T>
31inline constexpr bool IsPrimitiveShapeDef = false;
32
33// Identity specialization for arithmetic types. Fires a compile error for non-arithmetic types that
34// are missing a specialization.
35template <class T, class = void>
36struct ScalarTypeDef {
37 static_assert(
38 std::is_arithmetic_v<T>,
39 "ScalarType<T>: T is not a recognized scalar type and has no ScalarTypeDef specialization.");
40 using type = std::remove_cv_t<T>;
41};
42
43// Specialization for types exposing ::Scalar (e.g., Simd, Matrix, SparseMatrix).
44template <class T>
45struct ScalarTypeDef<T, std::void_t<typename T::Scalar>> {
46 using type = typename ScalarTypeDef<std::decay_t<typename T::Scalar>>::type;
47};
48
49} // namespace details
50
51#if MOCHI_LANGUAGE_CPP20
52template <typename T>
53concept IsConst = std::is_const_v<T>;
54
55template <typename T>
57
58template <typename T>
59concept IsArithmetic = std::is_arithmetic_v<T>;
60
61/// @brief Empty object when no value is needed.
62struct Void {};
63
64template <typename T>
65concept IsNotVoidObject = !std::is_same_v<Void, std::decay_t<T>>;
66
67template <typename T>
68concept IsPrimitiveShape = details::IsPrimitiveShapeDef<std::decay_t<T>>;
69#else
70template <typename T>
71inline constexpr bool IsPrimitiveShape = details::IsPrimitiveShapeDef<std::decay_t<T>>;
72
73#endif // MOCHI_LANGUAGE_CPP20
74
75// Underlying scalar type (type itself for scalar types, recursive unwrap for compound types such as
76// Simd, Matrix, NdArray, or Span).
77template <class T>
78using ScalarType = typename details::ScalarTypeDef<std::decay_t<T>>::type;
79
80} // namespace superdex
Empty object when no value is needed.
Definition concepts.h:62