public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Graziano Servizi <Graziano.Servizi@bo.infn.it>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: decltype
Date: Tue, 25 Feb 2014 15:50:00 -0000	[thread overview]
Message-ID: <CAH6eHdS6w4trENcxMLq-2TCsx7fCCaxFiUus+s6sWjPeBXQ4rQ@mail.gmail.com> (raw)
In-Reply-To: <530CBAC1.2040304@bo.infn.it>

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.

  reply	other threads:[~2014-02-25 15:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-25 15:46 decltype Graziano Servizi
2014-02-25 15:50 ` Jonathan Wakely [this message]
2014-02-25 17:17   ` decltype Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAH6eHdS6w4trENcxMLq-2TCsx7fCCaxFiUus+s6sWjPeBXQ4rQ@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=Graziano.Servizi@bo.infn.it \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).