C++ Logo

std-proposals

Advanced search

Re: fixed type parameter packs

From: Dominic Fandrey <isocpp.id_at_[hidden]>
Date: Wed, 12 Aug 2020 13:33:09 +0200
On 11/08/2020 12:52, Ville Voutilainen wrote:
> On Tue, 11 Aug 2020 at 13:45, Dominic Fandrey via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
>>
>> There is another feature I've been wondering why it doesn't exist.
>> I'll show this by example:
>>
>> ...
>>
>> An alternative use case:
>>
>> constexpr <typename T>
>> constexpr T min(T const & val) {
>> return val;
>> }
>>
>> template <typename T, T .. Ts>
>> constexpr T min(T const & lhs, Ts const & ... tail) {
>> auto const rhs = min<T>(tail ...);
>> return lhs < rhs ? lhs : rhs;
>> }
>>
>> This would allow explicitly giving a T for a whole parameter pack.
>
> #include <concepts>
> #include <string_view>
> #include <iostream>
>
> void f(std::convertible_to<std::string_view> auto&&... stringviews)
> {
> ((std::cout << stringviews << std::endl),...);
> }
>
> void g(std::same_as<std::string_view> auto&... stringviews)
> {
> ((std::cout << stringviews << std::endl),...);
> }
>
> int main()
> {
> std::string_view a("foo"),b("bar"),c("baz");
> f(a, b, c);
> g(a, b, c);
> }
>

And I guess I also could:

template <typename T> void f(std::convertible_to<T> auto & ... args);

That does what I want, thank you!

Received on 2020-08-12 06:36:35