GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
implicit_metafunction_for_toml11.h
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
8#ifndef DESIGNLAB_IMPLICIT_METAFUNCTION_FOR_TOML11_H_
9#define DESIGNLAB_IMPLICIT_METAFUNCTION_FOR_TOML11_H_
10
11#include <iostream>
12#include <string>
13#include <type_traits>
14#include <vector>
15
16#include "toml11_define.h"
17
18
21namespace designlab::impl
22{
23
27template <typename T, typename = void>
28struct has_into_toml : std::false_type {};
29
33template <typename T>
34struct has_into_toml<T, std::void_t<decltype(toml::into<T>())> > :
35 std::true_type {};
36
40template <typename T, typename = void>
41struct has_from_toml : std::false_type {};
42
46template <typename T>
47struct has_from_toml<T, std::void_t<decltype(toml::from<T>())> > :
48 std::true_type {};
49
50
54template<typename T, typename U = void>
55struct has_input_operator : public std::false_type {};
56
60template<typename T>
62 decltype(std::declval<std::istream&>() >> std::declval<T&>(),
63 std::declval<void>())> :
64 public std::true_type {};
65
69template<typename T, typename U = void>
70struct has_output_operator : public std::false_type {};
71
75template<typename T>
76struct has_output_operator<T, decltype(std::declval<std::ostream&>() << std::declval<T&>(), std::declval<void>())> : public std::true_type {};
77
78static_assert(has_input_operator<int>::value == true, "int型は入力オペレーターに対応している.");
79static_assert(has_input_operator<int*>::value == false, "int*型は入力オペレーターに対応していない.");
80static_assert(has_input_operator<std::vector<int>>::value == false, "std::vector<int>型は入力オペレーターに対応していない.");
81
82static_assert(has_output_operator<int>::value == true, "int型は出力オペレーターに対応している.");
83static_assert(has_output_operator<int*>::value == true, "int*型は出力オペレーターに対応している.");
84static_assert(has_output_operator<std::vector<int>>::value == false, "std::vector<int>型は出力オペレーターに対応していない.");
85
86
89template <typename T>
90struct is_vector : std::false_type {};
91
95template <typename T>
96struct is_vector<std::vector<T>> : std::true_type {};
97
98static_assert(is_vector<int>::value == false, "An int type is not a vector type.");
99static_assert(is_vector<std::string>::value == false, "std::string type is not a vector type.");
100
101static_assert(is_vector<std::vector<int>>::value == true, "The type std::vector<int> is a vector type.");
102static_assert(is_vector<std::vector<std::string>>::value == true, "The type std::vector<std::string> is a vector type.");
103
104
107template <typename T>
109{
110private:
111 template <typename U, typename = decltype(toml::get<U>(std::declval<toml::value>()))>
112 static std::true_type test(int);
113
114 template <typename>
115 static std::false_type test(...);
116
117public:
120 static constexpr bool value = decltype(test<T>(0))::value && !is_vector<T>::value;
121};
122
126template <typename T>
127struct is_toml11_available_type_vector_type : std::false_type {};
128
132template <typename T>
134
135static_assert(is_toml11_available_type_not_vector_type<int>::value == true, "The type int is a type that can be used in toml11.");
136static_assert(is_toml11_available_type_not_vector_type<int*>::value == false, "The type int* is not a usable type in toml11.");
137static_assert(is_toml11_available_type_not_vector_type<std::vector<int>>::value == false, "The type std::vector<int> is a std::vector type.");
138
139static_assert(is_toml11_available_type_vector_type<int>::value == false, "int type is not a std::vector type.");
140static_assert(is_toml11_available_type_vector_type<int*>::value == false, "int* type is not a std::vector type.");
141static_assert(is_toml11_available_type_vector_type<std::vector<int>>::value == true, "The type std::vector<int> is a type of std::vector and can used in toml11.");
142static_assert(is_toml11_available_type_vector_type<std::vector<int*>>::value == false, "type std::vector<*int> is a std::vector type, but it cannot use toml11.");
143
144
146template <typename T>
148 std::conditional_t<is_vector<T>::value,
149 is_toml11_available_type_vector_type<T>,
150 is_toml11_available_type_not_vector_type<T>> {};
151
152static_assert(
154 "Int is a type that can be used in toml11.");
155static_assert(
157 "The type int* is not a usable type in toml11.");
158static_assert(
160 "The type std::vector<int> is a type of std::vector and can be used in toml11.");
161static_assert(
163 "type std::vector<*int> is a std::vector type, but it is not a usable type.");
164
165
169template <typename T>
170struct is_vector_of_has_input_operator : std::false_type {};
171
175template <typename T>
177
181template <typename T>
182struct is_vector_of_has_output_operator : std::false_type {};
183
187template <typename T>
189
190
194template <typename T>
195struct is_vector_of_enum : std::false_type {};
196
199template <typename T>
200struct is_vector_of_enum<std::vector<T>> : std::is_enum<T> {};
201
202} // namespace designlab::impl
203
204
205#endif // DESIGNLAB_IMPLICIT_METAFUNCTION_FOR_TOML11_H_
明示的に使用することのない関数をまとめた名前空間.
Definition com_type.h:24
toml::from<T>()が存在するかどうかを判定するメタ関数.
入力ストリームが実装されているか判断するメタ関数.
toml::into<T>()が存在するかどうかを判定するメタ関数.
出力ストリームが実装されているか判断するメタ関数.
toml11で使用可能な型かどうかを判定するメタ関数. toml11は vector型にも対応しているが,こちらでは除外する.
static constexpr bool value
toml11 で使用可能な型ならば true. toml11は vector型にも対応しているが,こちらでは除外する.
toml11で使用可能な型かどうかを判定するメタ関数. vector型の場合はこちらを使用して判定する.
toml11で使用可能な型かどうかを判定するメタ関数.
vector<enum> 型かどうかを判定するメタ関数.
入力ストリームが実装されている vector 型かどうかを判定するメタ関数.
出力ストリームが実装されている vector 型かどうかを判定するメタ関数.
vector型かどうかを判定するメタ関数.