home bbs files messages ]

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 33,008 of 33,346   
   Daryle Walker to All   
   Method to get a noexcept-swap check?   
   30 Apr 13 12:48:42   
   
   From: darylew@googlemail.com   
      
   { Please limit your text to fit within 80 columns, preferably around 70,   
     so that readers don't have to scroll horizontally to read each line.   
     This article has been reformatted manually by the moderator. -mod }   
      
   I've read about people wondering how to do:   
      
   MyClass   
   {   
   public:   
       //...   
       void  swap( MyClass & ) noexcept( /*What goes here?*/ );   
       //...   
   };   
      
   The answer depends on the noexcept status of the internal component   
   types' swapping.  You could put calls to "swap" in the expression and   
   hope that ADL is invoked.  It would probably be complicated.  Then I   
   thought about C-level arrays.  C++11 adds a version of "std::swap" for   
   C-level arrays.  Since that will have a noexcept setting based on the   
   extents-stripped type, we could use that to universally check for swap:   
      
       noexcept( std::swap(std::declval(),   
        std::declval()) );   
      
   This assumes that the built-in array specialization of std::swap   
   calculates its noexcept status accurately (std::swap for built-ins,   
   ADL for UDTs, etc.).  It can even use compiler magic!  Mere users can't   
   access any of the magic they use (which may be implementation-dependent),   
   but we indirectly access it with this trick.   
      
   Is this viable?  Is there an easier alternative?   
      
   Daryle W.   
      
      
   --   
         [ 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