std::meta::is_swappable_with_type, std::meta::is_swappable_type, std::meta::is_nothrow_swappable_with_type, std::meta::is_nothrow_swappable_type - cppreference.com
Namespaces
Variants

std::meta::is_swappable_with_type, std::meta::is_swappable_type, std::meta::is_nothrow_swappable_with_type, std::meta::is_nothrow_swappable_type

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
Defined in header <meta>
consteval bool is_swappable_with_type( std::meta::info r1,
                                       std::meta::info r2 );
(1) (since C++26)
consteval bool is_swappable_type( std::meta::info r );
(2) (since C++26)
consteval bool is_nothrow_swappable_with_type( std::meta::info r1,
                                               std::meta::info r2 );
(3) (since C++26)
consteval bool is_nothrow_swappable_type( std::meta::info r );
(4) (since C++26)

Determines if the reflected types T, T1 and T2, represented by r, r1 and r2 respectively, are swappable.

1) Equivalent to return std::is_swappable_with_v<T1, T2>;.
2) Equivalent to return std::is_swappable_v<T>;.
3) Equivalent to return std::is_nothrow_swappable_with_v<T1, T2>;.
4) Equivalent to return std::is_nothrow_swappable_v<T>;.

Parameters

r, r1, r2 - reflection values to test

Return value

1,3) true if types T1 and T2 are swappable as described above. Otherwise, false.
2,4) true if type T is swappable as described above. Otherwise, false.

Exceptions

Throws std::meta::exception:

  • If any of r, r1, or r2 does not represent a type or type alias.
  • If any of T, T1, or T2 does not represent a complete type, (possibly cv-qualified) void, or an array of unknown bound.
  • If an instantiation of a template above depends, directly or indirectly, on an incomplete type, and that instantiation could yield a different result if that type were hypothetically completed.

Notes

These functions do not check anything outside the immediate context of the swap expressions: if the use of T1 or T2 would trigger template specializations, generation of implicitly-defined special member functions etc, and those have errors, the actual swap may not compile even if std::is_swappable_with_v<T1, T2> compiles and evaluates to true.

Example

#include <meta>
#include <vector>

static_assert
(
    is_swappable_type(^^int) and
    !is_swappable_with_type(^^int, ^^int) and
    is_nothrow_swappable_type(^^int) and
    !is_nothrow_swappable_with_type(^^int, ^^int) and
    is_swappable_type(^^std::vector<int>) and
    !is_swappable_with_type(^^int, ^^float) and
    !is_swappable_with_type(^^int, ^^char) and
"");

int main() {}

See also