Re: decltype

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This question is not about GCC so would be more appropriate in a
general C++ forum, e.g. stackoverflow.com


On 25 February 2014 15:46, Graziano Servizi wrote:
> Could you kindly explain to me how and when the decltype keyword do have a
> tilde character prefixed?
> I'm unable to figure out the cases in which such a syntax would be used and
> I found it as an example of an "id-expression" together with the name of a
> destructor: should be to explicitly call a destructor of some class?

Yes, it's used in a pseudo-destructor call.

For example, to destroy an object returned by a function:

template<typename Func>
void foo(Func f)
{
  auto obj = f();
  obj.~decltype(obj)();
}

This is equivalent to:

template<typename Func>
void foo(Func f)
{
  auto obj = f();
  using Object = decltype(obj);
  obj.~Object();
}

This syntax is very rarely needed.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux