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
...@@ -2278,10 +2278,8 @@ std::ostringstream ost; ...@@ -2278,10 +2278,8 @@ std::ostringstream ost;
- *Do not use the ellipsis notation for function arguments.* [<<no-ellipsis>>] - *Do not use the ellipsis notation for function arguments.* [<<no-ellipsis>>]
Functions with an unspecified number of arguments should not be used Prior to C++ 11, functions with an unspecified number of arguments
because they are a common cause of bugs that are hard to find. But had to be declared and used in a type-unsafe manner:
=catch(...)= to catch any exception is acceptable (but should generally
not be used outside of framework code).
#+BEGIN_EXAMPLE #+BEGIN_EXAMPLE
// avoid to define functions like: // avoid to define functions like:
...@@ -2290,6 +2288,24 @@ void error(int severity, ...) // "severity" followed by a ...@@ -2290,6 +2288,24 @@ void error(int severity, ...) // "severity" followed by a
// of char*s // of char*s
#+END_EXAMPLE #+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>>] - *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. ...@@ -3022,6 +3038,8 @@ The comment includes the fact that it is the perpendicular distance.
** Version 0.8 ** Version 0.8
- Clarify that non-ascii characters should not be used in identifier names. - 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 ** Version 0.7
- Minor cleanups and updates to take into acount that we now require C++17. - Minor cleanups and updates to take into acount that we now require C++17.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment