C++ 中重载函数右值引用和左值引用匹配的优先级

C++ 中重载函数右值引用和左值引用匹配的优先级

在使用 C++ STL 里的 std::regex 时,遇到了一个问题:

std::sregex_iterator it_begin(html.begin(), html.end(),
                               std::regex{R"raw("heading">.</h2>")raw"});

上面这种做法不行,原因是上面的代码可以匹配到下面代码:

 regex_token_iterator(_BidIt, _BidIt, const regex_type&&, int = 0,
        regex_constants::match_flag_type = regex_constants::match_default) = delete;

但是不能匹配到下面的代码:

 regex_token_iterator(_BidIt _First, _BidIt _Last, const regex_type& _Re, int _Sub = 0,
        regex_constants::match_flag_type _Fl = regex_constants::match_default)
        : _Pos(_First, _Last, _Re, _Fl), _Cur(0), _Subs(&_Sub, &_Sub + 1) {
        _Init(_First, _Last);
    }

验证:

static void
value_function(const int32_t &&ir)
{
  (void)wprintf_s(L"rvalue: %d\n", ir);
}

static void
value_function(const int32_t &il)
{
  (void)wprintf_s(L"lvalue: %d\n", il);
}

int wmain(int argc, wchar_t *argv[])
{
  value_function(1);
  int n{ 2 };
  value_function(n);
}

输出结果是:

rvalue: 1
lvalue: 2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dowhileprogramming

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值