C++ Logo

std-discussion

Advanced search

Re: Question regarding how to declare templated functions inside a concept declaration

From: Yongwei Wu <wuyongwei_at_[hidden]>
Date: Mon, 18 Apr 2022 13:14:43 +0800
On Mon, 18 Apr 2022 at 09:08, Marios Staikopoulos via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> ```
>
> template<typename T, typename B>
>
> concept EncryptionKey = requires(const T key, B& buf, const B& c_buf)
>
> {
>
> requires Buffer<B>;
>
>
>
> { key.EncryptFast(buf) } -> std::same_as<bool>;
>
> { key.EncryptFast(buf, c_buf) } -> std::same_as<bool>;
>
> };
>
> ```
>
> ... but what about this:
>
>
> ```
> template<Buffer B1, Buffer B2, Encryptionkey<???> K>
> void EncryptBufferHelper(B1& buf1, const B2& buf2, const K& key)
> {
> key.EncryptFast<B1, B2>(buf1, buf2);
> }
> ```
>

Maybe something like:

```
template<Buffer B, typename K>
requires EncryptionKey<K, B>
void EncryptBufferHelper(B& buf1, const B& buf2, const K& key)
{
               key.EncryptFast(buf1, buf2);
}
```

The shorthand notation (`Concept Type` within angle brackets) cannot be
used for multi-parameter concepts, and one generally needs to use the
requires clause instead.

Best regards,

Yongwei

Received on 2022-04-18 05:14:52