c++ - What is a proper way to implement is_swappable to test for the Swappable concept? -


I will consider the "proper" implementation for is_swappable for the following:

  Template & lt; Square t, square u = t & gt; Straight is_swappable & lt; T, U & gt; : / * See below * / {}  

is_swappable if T and U are, otherwise than


I have tried many things, but SFINAE just does not seem to work. This is a particularly nasty counting example:

  struct A {A () {} ~ A () {} A (const A & amp;) = delete; A (A & amp;) = Deletion; };  

Not explicitly a , but with any generic solution I can not handle the example coming up properly.

I have tried a SFINAE implementation, but did not work as seen:

  Namespace with_st_swap {std :: swap; Template & lt; Class t, class u, square = manifesto (swap (std :: declval & lt; t & gt; (), std :: declval & lt; u & gt; ())) gt; Std :: true_type swappable_test (int); Template & lt; Class, orbit & gt; Std :: false_type swappable_test (...); } Template & lt; Square t, class u = t & gt; Struct is_swappable: decltype (with_std_swap :: use_std_swap :: swappable_test & lt; t, u & gt; (0)) {};  

Is there a way to code is_swappable without compiler help? Building on the answer to Jrok, we can tell whether an ineligible swap call std:

as swap with the same code as std :: swap , but a unique return type that can be checked again: < / P>
  Namespace Details 2 {struct tag {}; Template & lt; Class T & gt; Tag swap (T & amp; amp; T & amp;;); Template & lt; Typename T & gt; Struct would_call_std_swap_impl {template & lt; Typename u & gt; Fixed auto check (int) - & gt; Std :: integral_constant & lt; Bool, std :: is_same & lt; Decltype (swap (std :: declval & lt; u & gt; (), std :: declval & lt; u & gt; ()), tag & gt; :: value & gt ;; The template's & lt; Typename & gt; Fixed std :: false_type check (...); Type = decltype use (check & lt; T & gt; (0)); }; Template & lt; Typename T & gt; Struct would_call_st_swap: would_call_std_swap_impl & lt; T & gt; :: type {}; }  

Then the definition of is_swappable is created:

  template & lt; Typename T & gt; Struct is_swappable: std :: integral_constant & lt; Bool, extension :: can_call_swap & lt; T & gt; :: Values ​​& amp; Amp; (Expansion 2 :: IICAl_STD_SPAP  :: value || (std :: is_move_assignable & lt; T & gt; :: Price & amp; std :: is_move_constructible & lt; T & gt; : Value (value)) & gt; {};  

We also need a special case for swapping arrays:

  template & lt; Typename T, std :: size_t N & gt; Straight is_swappable & lt; T [n] & gt; : Is_swappable & lt; T & gt; {};  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -