Jul 6, 2022

[C++] count bool 'true' snippet

template <bool B = false> constexpr auto count() -> size_t { return B ? 1 : 0; }

template <bool B1, bool B2, bool... Tail> constexpr auto count() -> size_t {
  return (B1 ? 1 : 0) + count<B2, Tail...>();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.