mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
add: [imp] copy_cvref
This commit is contained in:
parent
b75022b4a4
commit
43021c1aba
@ -84,4 +84,42 @@ struct is_specialized : std::false_type {};
|
||||
template <template <typename...> class Tt, typename... A>
|
||||
struct is_specialized<Tt, Tt<A...>> : std::true_type {};
|
||||
|
||||
/**
|
||||
* \brief Copy the cv qualifier and reference of the source type to the target type.
|
||||
*/
|
||||
template <typename Src, typename Des>
|
||||
struct copy_cvref {
|
||||
using type = Des;
|
||||
};
|
||||
|
||||
template <typename Src, typename Des>
|
||||
struct copy_cvref<Src const, Des> {
|
||||
using type = typename std::add_const<Des>::type;
|
||||
};
|
||||
|
||||
template <typename Src, typename Des>
|
||||
struct copy_cvref<Src volatile, Des> {
|
||||
using type = typename std::add_volatile<Des>::type;
|
||||
};
|
||||
|
||||
template <typename Src, typename Des>
|
||||
struct copy_cvref<Src const volatile, Des> {
|
||||
using type = typename std::add_cv<Des>::type;
|
||||
};
|
||||
|
||||
template <typename Src, typename Des>
|
||||
struct copy_cvref<Src &, Des> {
|
||||
using type = typename std::add_lvalue_reference<
|
||||
typename copy_cvref<Src, Des>::type>::type;
|
||||
};
|
||||
|
||||
template <typename Src, typename Des>
|
||||
struct copy_cvref<Src &&, Des> {
|
||||
using type = typename std::add_rvalue_reference<
|
||||
typename copy_cvref<Src, Des>::type>::type;
|
||||
};
|
||||
|
||||
template <typename Src, typename Des>
|
||||
using copy_cvref_t = typename copy_cvref<Src, Des>::type;
|
||||
|
||||
LIBIMP_NAMESPACE_END_
|
||||
|
||||
@ -134,3 +134,21 @@ TEST(utility, in_place) {
|
||||
[](std::in_place_t) {}(imp::in_place);
|
||||
}
|
||||
#endif/*LIBIMP_CPP_17*/
|
||||
|
||||
TEST(utility, copy_cvref) {
|
||||
EXPECT_TRUE((std::is_same<imp::copy_cvref_t<int , long>, long >()));
|
||||
EXPECT_TRUE((std::is_same<imp::copy_cvref_t<int & , long>, long & >()));
|
||||
EXPECT_TRUE((std::is_same<imp::copy_cvref_t<int &&, long>, long &&>()));
|
||||
|
||||
EXPECT_TRUE((std::is_same<imp::copy_cvref_t<int const , long>, long const >()));
|
||||
EXPECT_TRUE((std::is_same<imp::copy_cvref_t<int const & , long>, long const & >()));
|
||||
EXPECT_TRUE((std::is_same<imp::copy_cvref_t<int const &&, long>, long const &&>()));
|
||||
|
||||
EXPECT_TRUE((std::is_same<imp::copy_cvref_t<int volatile , long>, long volatile >()));
|
||||
EXPECT_TRUE((std::is_same<imp::copy_cvref_t<int volatile & , long>, long volatile & >()));
|
||||
EXPECT_TRUE((std::is_same<imp::copy_cvref_t<int volatile &&, long>, long volatile &&>()));
|
||||
|
||||
EXPECT_TRUE((std::is_same<imp::copy_cvref_t<int const volatile , long>, long const volatile >()));
|
||||
EXPECT_TRUE((std::is_same<imp::copy_cvref_t<int const volatile & , long>, long const volatile & >()));
|
||||
EXPECT_TRUE((std::is_same<imp::copy_cvref_t<int const volatile &&, long>, long const volatile &&>()));
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user