为什么std :: forward_list ::: remove和std :: erase 具有不同的值类型?

问题描述 投票:0回答:2

[std::forward_list具有member function

size_type remove(const T& value);

non-member function std::erase声明如下:

template<class T, class Alloc, class U>
typename forward_list<T, Alloc>::size_type
    erase(forward_list<T, Alloc>& c, const U& value);

[请注意,非成员函数std::eraseU的类型不同value;而成员函数remove只需将T键入value

为什么std::erase不只将T用作value

不一致之处背后是否有任何设计依据?

c++ templates standards c++20 design
2个回答
2
投票

cppreference.com所指出:


0
投票

我可以看到一个实际的原因。这与模板自变量推导带来的困难有关。想象一下这个假设函数:

© www.soinside.com 2019 - 2024. All rights reserved.