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
33template <typename T>
34inline constexpr bool IsSdfBvDef = false;
35
36// Identity specialization for arithmetic types. Fires a compile error for non-arithmetic types that
37// are missing a specialization.
38template <class T, class = void>
39struct ScalarTypeDef {
40 static_assert(
41 std::is_arithmetic_v<T>,
42 "ScalarType<T>: T is not a recognized scalar type and has no ScalarTypeDef specialization.");
43 using type = std::remove_cv_t<T>;
44};
45
46// Specialization for types exposing ::Scalar (e.g., Simd, Matrix, SparseMatrix).
47template <class T>
48struct ScalarTypeDef<T, std::void_t<typename T::Scalar>> {
49 using type = typename ScalarTypeDef<std::decay_t<typename T::Scalar>>::type;
50};
51
52} // namespace details
53
54#if MOCHI_LANGUAGE_CPP20
55template <typename T>
56concept IsConst = std::is_const_v<T>;
57
58template <typename T>
60
61template <typename T>
62concept IsArithmetic = std::is_arithmetic_v<T>;
63
64/// @brief Empty object when no value is needed.
65struct Void {};
66
67template <typename T>
68concept IsNotVoidObject = !std::is_same_v<Void, std::decay_t<T>>;
69
70template <typename T>
71concept IsPrimitiveShape = details::IsPrimitiveShapeDef<std::decay_t<T>>;
72
73template <typename T>
74concept IsSdfBv = details::IsSdfBvDef<std::decay_t<T>>;
75#else
76template <typename T>
77inline constexpr bool IsPrimitiveShape = details::IsPrimitiveShapeDef<std::decay_t<T>>;
78
79template <typename T>
80inline constexpr bool IsSdfBv = details::IsSdfBvDef<std::decay_t<T>>;
81
82#endif // MOCHI_LANGUAGE_CPP20
83
84// Underlying scalar type (type itself for scalar types, recursive unwrap for compound types such as
85// Simd, Matrix, NdArray, or Span).
86template <class T>
87using ScalarType = typename details::ScalarTypeDef<std::decay_t<T>>::type;
88
89} // namespace superdex
Empty object when no value is needed.
Definition concepts.h:65