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,011 of 33,346   
   Daryle Walker to Daryle Walker   
   Re: Method to get a noexcept-swap check?   
   30 Apr 13 22:41:58   
   
   From: darylew@googlemail.com   
      
   On Tuesday, April 30, 2013 3:48:42 PM UTC-4, Daryle Walker wrote:   
   > I've read about people wondering how to do:   
   >   
   > MyClass   
   > {   
   > public:   
   >     //...   
   >     void  swap( MyClass & ) noexcept( /*What goes here?*/ );   
   >     //...   
   > };   
   [SNIP]   
   > Is this viable?  Is there an easier alternative?   
      
   Why yes, yes there is.  I came up with it just after the first post.   
   We just combine "constexpr" with implementations on using ADL-swap:   
      
       #include    
      
       template < typename T >   
       inline constexpr   
       bool  is_swap_noexcept() noexcept   
       {   
           using std::swap;   
           return noexcept( swap(std::declval(),   
            std::declval()) );   
       }   
      
       // Example   
       template < typename T >   
       void  adl_swap( T &a, T &b ) noexcept( is_swap_noexcept() )   
       {   
           using std::swap;   
           swap( a, b );   
       }   
      
   No magic, or hoping of, needed.   
      
   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