我开始尝试概念的C ++ 20功能,当我意识到可以部分显式提供概念的模板参数时感到非常高兴。我阅读了cppreference文章,但没有找到那里提到的内容。
但是后来我意识到一些奇怪的事情:模板参数的指定顺序与我所期望的相反。提供一个显式模板参数时,它将替换模板列表中的第二个模板:
#include <concepts>
#include <type_traits>
/// Concept in order to deduce if sth. is base of sth else
template <typename Impl, typename Base> //XXX: here the order of Impl and Base are not
concept Implements = std::is_base_of_v<std::remove_reference_t<Base>, // what I would've expected.
std::remove_reference_t<Impl>>;
/// Example Base class impl
struct BaseExample {};
/// Implementation of BaseExample
struct ImplExample : BaseExample {};
/// Function in which the concept is applied
template <Implements<BaseExample>... Baes> void f(Baes &&... ) {}//} ((void)b, ...); }
int main() {
(void) std::is_base_of_v<BaseExample, std::remove_reference_t<ImplExample &&>>; //< true
(void) std::is_base_of_v<BaseExample, std::remove_reference_t<ImplExample&>>; //< true
f(ImplExample{}, ImplExample{});
}
从我的观点来看,部分提供显式模板参数的可能性是有意义的,因为针对类的部分模板规范的参数在这里并不适用,并且会使概念更笼统。现在我想知道:
可以找到代码here。
编辑发布后,我检查了指定三个模板参数时的行为。看来我误解了规范的顺序:第一个参数“自由持有”以包含要检查的参数,而显式的规范以第二个参数开头。可以看到here。即使我找出了说明顺序背后的原因,但我对以上问题的答案仍会非常感兴趣。
是,partial-concept-id肯定是C ++ 20。尽管令人惊讶,但第一个参数的特殊状态允许std::constructible_from
之类的情况声明为
std::constructible_from
template<class T,class ...Args>
concept constructible_from=…;
是type-constraint,requires所引入的任何内容都可以从两个std::constructible_from<int,int>
参数中构造出来。但是,它也可以是expression,在这种情况下,它是否是[[reports是否可以由int
构造int
(破坏者:int
),但是无论是否存在这种潜在的混乱都存在参数顺序。
true
,将无法使用这样的概念:只有模板参数推导或默认模板参数才能为模板参数提供超出参数pack
的值,而没有其中的适用于此处。您链接的论文网站上发布的每封邮件均包含标准的最新草案,替代邮件中包含有关采用哪些论文的注释。或者,您也可以访问T
(至少在您乐于阅读LaTeX的情况下)。