包含其他容器的容器的值类型
value type of containers that contain other containers
在这个问题 中提出了一个关于如何检查通用容器的值类型的解决方案,例如检查 std::vector
是否包含 integral
。现在,有时我可能会传递 2D 向量,即最终具有浮点或整数类型的容器的容器。
我们如何修改以下概念以包含此内容,以便 std::vector<std::vector<int>>
如果我们希望它包含整数类型,则不会失败。在我的应用程序中,超出 std::vector<std::vector<int>>
- 类似矩阵的数组是没有意义的。因此解决方案不需要检查无限嵌套容器。
template< typename U, typename Tin, typename Tout>
concept MyConditions =
requires
{
typename U::value_type;
typename Tin::value_type;
typename Tout::value_type;
requires std::integral<typename T::value_type>;
requires std::floating_point<typename U::value_type>;
requires std::floating_point<typename Tout::value_type>;
};
How do I extract the value type of the most nested container?
用户 Evg 在此 中显示了类型特征。
使用它,这应该可以工作:
template< typename U, typename Tin, typename Tout>
concept MyConditions =
requires
{
typename U::value_type;
typename Tin::value_type;
typename Tout::value_type;
// note, I suspect that you have a typo in T,
// which isn't declared. Did you mean Tin?
requires std::integral<inner_type_t<T>>;
requires std::floating_point<inner_type_t<U>>;
requires std::floating_point<inner_type_t<Tout>>;
};
在这个问题 std::vector
是否包含 integral
。现在,有时我可能会传递 2D 向量,即最终具有浮点或整数类型的容器的容器。
我们如何修改以下概念以包含此内容,以便 std::vector<std::vector<int>>
如果我们希望它包含整数类型,则不会失败。在我的应用程序中,超出 std::vector<std::vector<int>>
- 类似矩阵的数组是没有意义的。因此解决方案不需要检查无限嵌套容器。
template< typename U, typename Tin, typename Tout>
concept MyConditions =
requires
{
typename U::value_type;
typename Tin::value_type;
typename Tout::value_type;
requires std::integral<typename T::value_type>;
requires std::floating_point<typename U::value_type>;
requires std::floating_point<typename Tout::value_type>;
};
How do I extract the value type of the most nested container?
用户 Evg 在此
使用它,这应该可以工作:
template< typename U, typename Tin, typename Tout>
concept MyConditions =
requires
{
typename U::value_type;
typename Tin::value_type;
typename Tout::value_type;
// note, I suspect that you have a typo in T,
// which isn't declared. Did you mean Tin?
requires std::integral<inner_type_t<T>>;
requires std::floating_point<inner_type_t<U>>;
requires std::floating_point<inner_type_t<Tout>>;
};