Skip to content
Snippets Groups Projects
Commit 95cba03a authored by scott snyder's avatar scott snyder
Browse files

Clarify that variable-length argument lists of varadic template functions are ok.

parent 9eeb35e4
No related branches found
No related tags found
No related merge requests found
......@@ -2278,10 +2278,8 @@ std::ostringstream ost;
- *Do not use the ellipsis notation for function arguments.* [<<no-ellipsis>>]
Functions with an unspecified number of arguments should not be used
because they are a common cause of bugs that are hard to find. But
=catch(...)= to catch any exception is acceptable (but should generally
not be used outside of framework code).
Prior to C++ 11, functions with an unspecified number of arguments
had to be declared and used in a type-unsafe manner:
#+BEGIN_EXAMPLE
// avoid to define functions like:
......@@ -2290,6 +2288,24 @@ void error(int severity, ...) // "severity" followed by a
// of char*s
#+END_EXAMPLE
This method should be avoided.
As of C++ 11, one can accomplish something similar using varadic
templates:
#+BEGIN_EXAMPLE
template<typename ...ARGS>
void error(int severity, ARGS...)
#+END_EXAMPLE
This is fine, but should be used judiciously. It's appropriate
for forwarding arguments theough a template function. For other cases,
it's worth thinking if there might be a simpler way of doing things.
An ellipsis can also occur in a catch clause to catch any
exception: =catch(...)=. This is acceptable, but should generally
be restricted to framework-like code.
- *Do not use preprocessor macros to take the place of functions, or for defining constants.* [<<no-macro-functions>>]
......@@ -3022,6 +3038,8 @@ The comment includes the fact that it is the perpendicular distance.
** Version 0.8
- Clarify that non-ascii characters should not be used in identifier names.
- Clarify that variable-length argument lists of varadic template functions
are ok.
** Version 0.7
- Minor cleanups and updates to take into acount that we now require C++17.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment