C++ Logo

std-discussion

Advanced search

Re: Explicit and implicit parameter counts

From: Andrew Schepler <aschepler_at_[hidden]>
Date: Fri, 3 Sep 2021 11:49:10 -0400
Even the "simple" solution of adding a little data in the stack requires a
breaking ABI change, which would be a big deal. It's also a violation of
the C++ principle "you don't pay for what you don't use." I could see a
compiler extension providing this for only functions specifically tagged
with some attribute, if it were considered useful enough. From there to the
Standard would be a harder step.

But you can also get this behavior without extreme trouble just in the
existing language. Define functions with that extra parameter, and use a
callable class template object to wrap each with the wanted usage. A few
preprocessor macros might help reduce the code for defining such a function.

-- Andrew Schepler

On Fri, Sep 3, 2021, 11:16 AM Rick C. Hodgin via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> The 1) and 2) options outlined in the initial post (for referencing
> the passed in counts in code and being able to make logic decisions
> with that information, and for conditional compilation).
>
> IMO though, and most importantly, it completes the set of features
> related to default parameter assignments.
>
> --
> Rick C. Hodgin
>
> On 9/3/21, Oleksandr Koval <oleksandr.koval.dev_at_[hidden]> wrote:
> > For something to be added in the standard there should be a good
> > motivation, what's your motivation for this feature?
> >
> > On Fri, Sep 3, 2021 at 5:49 PM Rick C. Hodgin via Std-Discussion <
> > std-discussion_at_[hidden]> wrote:
> >
> >> Greetings.
> >>
> >> Since we can define explicitly required parameters, and implicitly
> >> required parameters (populated with default values), I'd like to
> >> propose a way to know the number of each provided to a function by its
> >> caller.
> >>
> >> This information would be available for use in two ways depending on
> >> how it's referenced:
> >>
> >> (1) As add-on named function parameters for use as use variables (for
> >> output, storage, or passing as parameters to other functions). These
> >> would be auto-added to the function's parameters by the compiler,
> >> though invisible to the user unless an examination of the stack was
> >> made:
> >>
> >> (2) As compile-time definitions which allow for conditional
> >> compilation, which would ultimately create versions of a function
> >> based on provided counts and the subsequent reference-only logic.
> >>
> >> [snip]
> >>
> >> --
> >> Rick C. Hodgin
> >> --
> >> Std-Discussion mailing list
> >> Std-Discussion_at_[hidden]
> >> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> >>
> >
> >
> > --
> > Regards,
> > Oleksandr Koval.
> >
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>

Received on 2021-09-03 10:49:26