descr.h
Go to the documentation of this file.
1 /*
2  pybind11/detail/descr.h: Helper type for concatenating type signatures at compile time
3 
4  Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
5 
6  All rights reserved. Use of this source code is governed by a
7  BSD-style license that can be found in the LICENSE file.
8 */
9 
10 #pragma once
11 
12 #include "common.h"
13 
16 
17 #if !defined(_MSC_VER)
18 # define PYBIND11_DESCR_CONSTEXPR static constexpr
19 #else
20 # define PYBIND11_DESCR_CONSTEXPR const
21 #endif
22 
23 /* Concatenate type signatures at compile time */
24 template <size_t N, typename... Ts>
25 struct descr {
26  char text[N + 1]{'\0'};
27 
28  constexpr descr() = default;
29  // NOLINTNEXTLINE(google-explicit-constructor)
30  constexpr descr(char const (&s)[N + 1]) : descr(s, make_index_sequence<N>()) {}
31 
32  template <size_t... Is>
33  constexpr descr(char const (&s)[N + 1], index_sequence<Is...>) : text{s[Is]..., '\0'} {}
34 
35  template <typename... Chars>
36  // NOLINTNEXTLINE(google-explicit-constructor)
37  constexpr descr(char c, Chars... cs) : text{c, static_cast<char>(cs)..., '\0'} {}
38 
39  static constexpr std::array<const std::type_info *, sizeof...(Ts) + 1> types() {
40  return {{&typeid(Ts)..., nullptr}};
41  }
42 };
43 
44 template <size_t N1, size_t N2, typename... Ts1, typename... Ts2, size_t... Is1, size_t... Is2>
45 constexpr descr<N1 + N2, Ts1..., Ts2...> plus_impl(const descr<N1, Ts1...> &a,
46  const descr<N2, Ts2...> &b,
50  return {a.text[Is1]..., b.text[Is2]...};
51 }
52 
53 template <size_t N1, size_t N2, typename... Ts1, typename... Ts2>
54 constexpr descr<N1 + N2, Ts1..., Ts2...> operator+(const descr<N1, Ts1...> &a,
55  const descr<N2, Ts2...> &b) {
57 }
58 
59 template <size_t N>
60 constexpr descr<N - 1> const_name(char const (&text)[N]) {
61  return descr<N - 1>(text);
62 }
63 constexpr descr<0> const_name(char const (&)[1]) { return {}; }
64 
65 template <size_t Rem, size_t... Digits>
66 struct int_to_str : int_to_str<Rem / 10, Rem % 10, Digits...> {};
67 template <size_t... Digits>
68 struct int_to_str<0, Digits...> {
69  // WARNING: This only works with C++17 or higher.
70  static constexpr auto digits = descr<sizeof...(Digits)>(('0' + Digits)...);
71 };
72 
73 // Ternary description (like std::conditional)
74 template <bool B, size_t N1, size_t N2>
75 constexpr enable_if_t<B, descr<N1 - 1>> const_name(char const (&text1)[N1], char const (&)[N2]) {
76  return const_name(text1);
77 }
78 template <bool B, size_t N1, size_t N2>
79 constexpr enable_if_t<!B, descr<N2 - 1>> const_name(char const (&)[N1], char const (&text2)[N2]) {
80  return const_name(text2);
81 }
82 
83 template <bool B, typename T1, typename T2>
84 constexpr enable_if_t<B, T1> const_name(const T1 &d, const T2 &) {
85  return d;
86 }
87 template <bool B, typename T1, typename T2>
88 constexpr enable_if_t<!B, T2> const_name(const T1 &, const T2 &d) {
89  return d;
90 }
91 
92 template <size_t Size>
94  return int_to_str<Size / 10, Size % 10>::digits;
95 }
96 
97 template <typename Type>
99  return {'%'};
100 }
101 
102 // If "_" is defined as a macro, py::detail::_ cannot be provided.
103 // It is therefore best to use py::detail::const_name universally.
104 // This block is for backward compatibility only.
105 // (The const_name code is repeated to avoid introducing a "_" #define ourselves.)
106 #ifndef _
107 # define PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY
108 template <size_t N>
109 constexpr descr<N - 1> _(char const (&text)[N]) {
110  return const_name<N>(text);
111 }
112 template <bool B, size_t N1, size_t N2>
113 constexpr enable_if_t<B, descr<N1 - 1>> _(char const (&text1)[N1], char const (&text2)[N2]) {
114  return const_name<B, N1, N2>(text1, text2);
115 }
116 template <bool B, size_t N1, size_t N2>
117 constexpr enable_if_t<!B, descr<N2 - 1>> _(char const (&text1)[N1], char const (&text2)[N2]) {
118  return const_name<B, N1, N2>(text1, text2);
119 }
120 template <bool B, typename T1, typename T2>
121 constexpr enable_if_t<B, T1> _(const T1 &d1, const T2 &d2) {
122  return const_name<B, T1, T2>(d1, d2);
123 }
124 template <bool B, typename T1, typename T2>
125 constexpr enable_if_t<!B, T2> _(const T1 &d1, const T2 &d2) {
126  return const_name<B, T1, T2>(d1, d2);
127 }
128 
129 template <size_t Size>
131  return const_name<Size>();
132 }
133 template <typename Type>
134 constexpr descr<1, Type> _() {
135  return const_name<Type>();
136 }
137 #endif // #ifndef _
138 
139 constexpr descr<0> concat() { return {}; }
140 
141 template <size_t N, typename... Ts>
142 constexpr descr<N, Ts...> concat(const descr<N, Ts...> &descr) {
143  return descr;
144 }
145 
146 #ifdef __cpp_fold_expressions
147 template <size_t N1, size_t N2, typename... Ts1, typename... Ts2>
148 constexpr descr<N1 + N2 + 2, Ts1..., Ts2...> operator,(const descr<N1, Ts1...> &a,
149  const descr<N2, Ts2...> &b) {
150  return a + const_name(", ") + b;
151 }
152 
153 template <size_t N, typename... Ts, typename... Args>
154 constexpr auto concat(const descr<N, Ts...> &d, const Args &...args) {
155  return (d, ..., args);
156 }
157 #else
158 template <size_t N, typename... Ts, typename... Args>
159 constexpr auto concat(const descr<N, Ts...> &d,
160  const Args &...args) -> decltype(std::declval<descr<N + 2, Ts...>>()
161  + concat(args...)) {
162  return d + const_name(", ") + concat(args...);
163 }
164 #endif
165 
166 template <size_t N, typename... Ts>
167 constexpr descr<N + 2, Ts...> type_descr(const descr<N, Ts...> &descr) {
168  return const_name("{") + descr + const_name("}");
169 }
170 
operator,
Eigen::CommaInitializer< XprType > & operator,(Eigen::CommaInitializer< XprType > &ci, double v)
Definition: special_functions.cpp:21
B
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
array
int array[24]
Definition: Map_general_stride.cpp:1
Chars
std::vector< char > Chars
Definition: QPSParser.cpp:48
index_sequence
Index sequences.
Definition: wrap/pybind11/include/pybind11/detail/common.h:685
s
RealScalar s
Definition: level1_cplx_impl.h:126
const_name
constexpr descr< N - 1 > const_name(char const (&text)[N])
Definition: descr.h:60
d
static const double d[K][N]
Definition: igam.h:11
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
b
Scalar * b
Definition: benchVecAdd.cpp:17
remove_cv_t
typename std::remove_cv< T >::type remove_cv_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:658
plus_impl
constexpr descr< N1+N2, Ts1..., Ts2... > plus_impl(const descr< N1, Ts1... > &a, const descr< N2, Ts2... > &b, index_sequence< Is1... >, index_sequence< Is2... >)
Definition: descr.h:45
PYBIND11_NAMESPACE_END
#define PYBIND11_NAMESPACE_END(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:80
detail
Definition: testSerializationNonlinear.cpp:70
PYBIND11_NAMESPACE_BEGIN
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:76
descr
Definition: descr.h:25
descr::types
static constexpr std::array< const std::type_info *, sizeof...(Ts)+1 > types()
Definition: descr.h:39
descr::text
char text[N+1]
Definition: descr.h:26
PYBIND11_NAMESPACE
Definition: test_custom_type_casters.cpp:24
T2
static const Pose3 T2(Rot3::Rodrigues(0.3, 0.2, 0.1), P2)
concat
constexpr descr< 0 > concat()
Definition: descr.h:139
common.h
descr::descr
constexpr descr(char const (&s)[N+1], index_sequence< Is... >)
Definition: descr.h:33
type_descr
constexpr descr< N+2, Ts... > type_descr(const descr< N, Ts... > &descr)
Definition: descr.h:167
int_to_str
Definition: descr.h:66
descr::descr
constexpr descr(char const (&s)[N+1])
Definition: descr.h:30
test_docs.d2
d2
Definition: test_docs.py:29
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100
#define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...)
Definition: wrap/pybind11/include/pybind11/detail/common.h:1230
make_index_sequence
typename make_index_sequence_impl< N >::type make_index_sequence
Definition: wrap/pybind11/include/pybind11/detail/common.h:693
args
Definition: pytypes.h:2210
operator+
constexpr descr< N1+N2, Ts1..., Ts2... > operator+(const descr< N1, Ts1... > &a, const descr< N2, Ts2... > &b)
Definition: descr.h:54
N
#define N
Definition: igam.h:9
descr::descr
constexpr descr(char c, Chars... cs)
Definition: descr.h:37
T1
static const Similarity3 T1(R, Point3(3.5, -8.2, 4.2), 1)
_
constexpr descr< N - 1 > _(char const (&text)[N])
Definition: descr.h:109
enable_if_t
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Definition: wrap/pybind11/include/pybind11/detail/common.h:654
relicense.text
text
Definition: relicense.py:59
descr::descr
constexpr descr()=default


gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:01:02