c++ - Fold expressions and empty parameters pack: what's the expected result? -


consider following minimal example:

#include<cstddef>  template<std::size_t... i> constexpr auto sum() { return (i + ...); }  template<bool... b> constexpr auto check() { return (b && ...); }  int main() {     static_assert(6 == sum<1,2,3>(), "!");     // static_assert(0 == sum<>(), "!");     static_assert(check<true, true>(), "!");     static_assert(check<>(), "!"); } 

the commented line doesn't compile.
same applies using * instead of +.
1 involving booleans works instead.

here (working draft) haven't found mentions empty parameter packs.
on other side, here (isocpp) seems default result in case above int().

what's expected behavior when mixing fold expressions , empty parameters pack?

this covered in [temp.variadic]¶9 (citing n4618):

if n 0 unary fold-expression, value of expression shown in table 14; if operator not listed in table 14, instantiation ill-formed.

table 14 — value of folding empty sequences:

operator  |  value when parameter pack empty   ----------------------------------------------- &&        |  true ||        |  false ,         |  void() 

the reason these 3 operators supported outlined in p0036r0.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -