isocpp / isocpp/CppCoreGuidelines

T.100 Suggested Example

Open
#2,093 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
45.3k
Forks
5.6k
PR merge metrics
No merged PRs in 30d

Description

template<typename... T>
void print_all(const T& ...args) {
    (output(args), ...);
}

print_all(a, 0, string{"xyz"}); // good, type-safe

printf("%d %d %s", a, 0, "xyz"); // bad, UB if %d the wrong specifier for a,
                                 // UB if we use std::string

I think this example demonstrates nicely how variadic functions are a "just works" solution and what safety issues arise with printf by comparison.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's proposed C++ variadic-template and printf example, then locate the relevant guideline section in the repository. Done means the example is added in an appropriate place and clearly demonstrates type safety and the printf undefined-behavior risks described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.