Boost logo

Boost Users :

Subject: Re: [Boost-users] function template with a universal reference to a specific type
From: Ireneusz Szcześniak (irek.szczesniak_at_[hidden])
Date: 2018-12-31 10:04:52


On 31.12.2018 10:20, degski wrote:

> 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.

I used __PRETTY_FUNCTION__ to make sure that the function is
instantiated with the template argument deduced as I expected. I
didn't use parameter t, because it was not relevant to the problem.

I can provide function overloads or more function templates for
various arguments the function could be called with:

class A {};

void foo(A &a) {}
void foo(const A &a) {}
void foo(A &&a) {}

and for templated types:

template <typename T>
class B {};

template<typename T>
void foo(B<T> &a) {}

template<typename T>
void foo(const B<T> &a) {}

template<typename T>
void foo(B<T> &&a) {}

But it would be more generic to provide a single function
implementation, and that's my motivation.

Best,
Irek


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