How come a concept receives 2 template parameters but only one is used?

How come a concept receives 2 template parameters but only one is used?


Here is use of concept Arithmetic in requires clause (2 template parameters)

1
2
3
4
5
6
7
8
9
10
template<typename Seq, typename Num>
requires Sequence<Seq> && Number<Num> && Arithmetic<range_value_t<Seq>, Num>
Num sum2(const Seq& seq, Num v)
{
	for (const auto& x : seq)
	{
		v += x;
	}
	return v;
}


Here is use of concept Arithmetic short syntax version (1 template parameter)

1
2
3
4
5
6
7
8
9
template<Sequence Seq, Arithmetic<range_value_t<Seq>> Num>
Num sum3(const Seq& seq, Num v)
{
	for (const auto& x : seq)
	{
		v += x;
	}
	return v;
}


??
Last edited on
There are two syntaxes involved, both of which ultimately supply the same number of parameters, just in different ways.

Either
  template <typename T>
  requires Concept<T>

Or
  template< Concept T >

Either
  template <typename T, typename U>
  requires Concept1<T> && Concept2<T, U>

Or
  template< Concept1 T, Concept2<T> U >

Note that the sum3 example does not apply the Number concept to Num, so it's a little different from the sum2 example.
Topic archived. No new replies allowed.