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 32,660 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to Zhihao Yuan   
   Re: How to write an is_nothrow_swapable<   
   21 Nov 12 12:42:25   
   
   From: daniel.kruegler@googlemail.com   
      
   On 2012-11-16 10:13, Zhihao Yuan wrote:   
   > Non-throw swapable is quite useful, and it can be more useful if the   
   > concept can be tested.  If we already have an object of type T, I   
   > think the following one is enough:   
   >   
   > template    
   > constexpr bool is_nothrow_swapable(T& t) {   
   > 	using std::swap;   
   > 	return noexcept(swap(t, t)) or   
   > 		(std::is_nothrow_move_constructible::value and   
   > 		 std::is_nothrow_move_assignable::value);   
   > }   
   >   
   > However, I want it to be able to work on just a type, to work as an   
   > integral_constant.  Is that doable?  Comments on how to implement an   
   > is_swapable are also welcome.  Thanks.   
      
   I'm not sure whether I understood your question correctly, because you   
   mention (a) the ability to work on just a type and (b) you refer to   
   is_swapable (instead of is_nothrow_swapable). I guess that (b) is just a   
   thinko on your side. What about a variation of your constexpr function   
   so that it does not depend on any argument anymore:   
      
   template    
   constexpr bool is_nothrow_swappable() {   
       using std::swap;   
       return noexcept(swap(std::declval(), std::declval())) or   
   		(std::is_nothrow_move_constructible::value and   
   		 std::is_nothrow_move_assignable::value);   
   }   
      
   template   
   struct is_nothrow_swappable_trait :   
       std::integral_constant()>   
   {   
   };   
      
   ?   
      
   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