Boost logo

Boost Users :

Subject: Re: [Boost-users] function template with a universal reference to a specific type
From: degski (degski_at_[hidden])
Date: 2018-12-31 09:20:24


On Mon, 31 Dec 2018 at 10:00, Ireneusz Szcześniak via Boost-users <
boost-users_at_[hidden]> wrote:

> Thank you for your email, but you missed the point of my email.
>

Possibly.

Please note that in the foo function I'm not using parameter t, so the
> use of the forwarding (universal) reference cannot be inappropriate.
>

I assumed __PRETTY_FUNCTION__ was doing something with t. If that is not
doing something with t, what are you pretty printing then? Are you saying
that you want to print something different depending upon the type [but
unrelated to the value of t]? Overloading is still the [an] answer, though.
It would be helpful if you state more clearly what you want to do and why
you think you need a UR. This SO-question goes into some depth to explain
the differences [it's more intricate than it seems, but once you got the
hang of it in practice it's quite easy]. In the case of PODs [as in your
examples], all this is rather moot, and you can just as well use
value-semantics.

template<typename Stream>
[[ maybe_unused ]] Stream & operator << ( Stream & out_, const point2f & )
noexcept {
    out_ << "I'm using a type called point2f";
    return out_;
}

A parameter that's not used does not have to have a name.

degski

-- 
*“If something cannot go on forever, it will stop" - Herbert Stein*


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net