Compound Argument Declaration

To make my code more concise, can I do something like

int f(int const x, y, z), g(int const x, y, z);

to declare functions f and g, each of which takes three arguments int const?

Edit : Perhaps here is a better example:

int f(int const a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z);

How would it be no more concise and readable than putting an int const in front of each letter?

+3
source share
6 answers

Using the Boost preprocessor and considering that you don't want to describe function arguments one by one (but this is not the point of your question), you can use the following trick:

#include <boost/preprocessor/repetition/enum_params.hpp>

int f( BOOST_PP_ENUM_PARAMS(26, int const arg) );

But do not forget that the whole idea of ​​not taking the required time and space to describe function arguments is very dangerous.

+2
source

C, , (K & R):

typedef int const cint;

int f(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
 cint a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
{
    // function body here
}

, , ++ , , , C extern "C" ++.

, . -, , , , . -, const (.. , , ) , (IMO) .

+4

, std::/std:: tr1::/boost:: array<int, count> const&. .

+1

.

, , .

, ++ .

0

, . , "" , . , . , ++ ( , ). , , .

0

Why do you need this? Entering a few extra characters doesn't really matter. If you need this more than a few methods, you should reorganize the code, so you do not need to pass many parameters.

Having said that in some cases, the right solution may be to use variational functions, so you can do:

int f(const int arg1, ...)
0
source

Source: https://habr.com/ru/post/1756113/


All Articles