我无法理解如何以及是否可以使用以下概念:
template <typename Type1, typename Type2>
concept StdByteContainer =
(std::same_as<Type1,std::remove_cvref_t<std::basic_string<Type2>>>
|| std::same_as<Type1,std::remove_cvref_t<std::vector<Type2>>>
|| std::same_as<Type1,std::remove_cvref_t<std::list<Type2>>>
|| std::same_as<Type1,std::remove_cvref_t<std::deque<Type2>>>
|| std::same_as<Type1,std::remove_cvref_t<std::set<Type2>>>)
&& (std::same_as<Type2,std::byte>
|| (std::is_integral_v<Type2> && sizeof(Type2)==1));
我试着这样写:
template <StdByteContainer Type1<Type2>>
void function(const Type1<Type2>& container);
所以:
template <StdByteContainer Type1, StdByteContainer Type2>
void function(const Type1<Type2>& container);
所以:
template <StdByteContainer Type1, Type2>
void function(const Type1<Type2>& container);
所以:
template <StdByteContainer Type1 Type2>
void function(const Type1<Type2>& container);
它不起作用,静态分析器写道:
error: 'StdByteContainer' requires more than 1 template argument
完全可以这样写,还是这样的概念基本不能接受?尽管解析器错过了概念的声明,但认为它是有效的......如果有的话,我使用GCC-10.
显然这个想法是一个参数是容器的类型,另一个是存储在这个容器中的对象的类型。但是,这对我来说似乎是多余的。我用一个模板参数做了一个这样的例子,并检查了依赖类型。
https://godbolt.org/z/h5E1je