LearnFrenzy
Sign in Take a free test

Templates · Templates MCQ · Question 11

if constexpr versus a normal if in templates Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 11 Back to Exercise

Why use if constexpr rather than if inside a template?

  • A It is faster at run time
  • B The untaken branch is discarded at compile time, so it may contain code that would not compile for that type Correct
  • C It allows run-time types
  • D It works outside templates only
Correct Answer: Option B

With a normal if, both branches must compile for every T.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links