【发布时间】:2021-02-07 03:02:25
【问题描述】:
我想写一个概念,让我可以使用 ADL 验证给定语句是否有效并具有正确的返回类型。
在我的具体情况下,我想编写一个 String 概念,它应该强制执行以下要求:
-
该类型的
const和非const风格具有begin和end语义:// Akin to what this function does for `T` and `T const` template< typename T > auto test(T& t) { using std::begin; return begin(t); } // calling test with `T` and `T const` should be valid. -
begin和end的返回类型对于const和非const风格是一致的,并且它们满足std::contiguous_iterator概念。
到目前为止,我使用的 trait 实现如下:
namespace Adl {
using std::begin;
template< typename T >
using HasBeginT = decltype(begin(std::declval< T >()));
}
template< typename T >
using HasBegin = std::experimental::is_detected< Adl::HasBeginT, T >;
但我想直接将此 ADL 用法嵌入到我的约束定义中。
【问题讨论】:
-
有什么原因你不能只使用
contiguous_range?