小编Sou*_*Roy的帖子

调用专门的std :: move()

我对如何在下面的例子中进行模板参数推断感到困惑.我在本文的其余部分使用术语invoke来暗示实例化和调用.

我专注std::move()于我的自定义类型my_type,我观察到,对于x类型的实例my_type:

  1. std::move(x) 继续调用通用模板
  2. std::move(static_cast<my_type&&>(x))std::move(std::forward(x))调用专业化
  3. 在没有我的专业化的情况下,所有上述调用都会调用通用模板

我的问题是:

  • 为什么上面第1项中的调用没有调用专门化?
  • 在没有专业化的情况下,#1和#2项中的调用如何表现相同?

这是整个代码:

#include<iostream>
#include<utility>

struct my_type
{
    int x;
};

namespace std
{

// This is the std::move() definition in the preprocessor output:
//
// template <class _Tp>
// inline __attribute__ ((__visibility__("hidden"), __always_inline__)) constexpr
// typename remove_reference<_Tp>::type&&
// move(_Tp&& __t) noexcept
// {
//     typedef typename remove_reference<_Tp>::type _Up;
//     return static_cast<_Up&&>(__t);
// }

// This is std::move() …
Run Code Online (Sandbox Code Playgroud)

c++ stl template-specialization move-semantics c++11

2
推荐指数
1
解决办法
158
查看次数