Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,261 of 33,346    |
|    =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All    |
|    Re: Explicit destructor call - problem w    |
|    09 May 12 14:57:02    |
      50876cc6       From: daniel.kruegler@googlemail.com              Am 09.05.2012 21:26, schrieb PiotrN:       > Two questions:       > 1) Why I cannot call destructor for builtin types like int:       > int a;       > int* p = new (&a) int(7);       > p->~int();       >       > I found in the NET that standard says: "The notation for explicit call       > of a destructor can be used for any scalar type name. Allowing this       > makes it possible to write code without having to know if a destructor       > exists for a given type. "              Yes, this is roughly the rationale for it: To be able to write generic       code without much trickery to discriminate scalar types from class       types. The more precise rule is that the pseudo-destructor name is valid       for scalar types only, if these are provided as /type-name/ (like a       typedef) or a decltype-specifier (like: decltype(0)).              > And typedef int is "scalar type name" but int is not - so it works the       > following:       > typedef int INT;       > p->~INT();       > Why standard does allow calling destructor on typedef (and template       > typename) - but it has objections to plain type? Is there any       > rationale for this?              Only a weak one: Once you are in non-template code, you have knowledge       of the specific type, so why bothering with writing a no-op? This *is*       really a weak argument, because you have the same problem once you would       try to write a generic macro. In other words: I wish, we would not have       this constraint to support the pseudo-destructor only for type-names and       decltype-specifiers when we have a non-class type.              > 2) Why C++ (gcc-4.3.4) has objections to this syntax:       >       > p->std::~string();       >       > of course this works well:       >       > using namespace std;       > p->~string();              You can write this as:              p->std::string::~string();              HTH & Greetings from Bremen,              Daniel Krügler                     --        [ See http://www.gotw.ca/resources/clcm.htm for info about ]        [ comp.lang.c++.moderated. First time posters: Do this! ]              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca