且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

算法实现

更新时间:2023-02-26 18:13:21

Fraser Ross写道:
Fraser Ross wrote:

template< class OutputIterator,class Size,class T>

void fill_n(OutputIterator first,size n,const T& value)

{

while(n-- 0)* first ++ = value;

}


如果Size必须可以转换为整数类型,这不是

实现,它排除了将枚举值作为第二个传递

参数?枚举值可以转换为整数类型,因此

实现与规范不匹配。
template <class OutputIterator, class Size, class T>
void fill_n (OutputIterator first, Size n, const T& value)
{
while (n-- 0) *first++ = value;
}

If Size must be convertible to an integral type is this not an
implementation that excludes passing an enum value as the second
parameter? An enum value is convertible to an integral type so the
implementation does not match the specification.



正确。你在哪里找到这个?更好的方法是制作




void fill_n(首先是OutputIterator,大小为n_arg,const T& value)

{

size_t n = n_arg; ...


,可能。


V

-

请在通过电子邮件回复时删除资本''A'

我没有回复最热门的回复,请不要问

Correct. Where did you find this one? A better way would be to make
it

void fill_n (OutputIterator first, Size n_arg, const T& value)
{
size_t n = n_arg; ...

, probably.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


Victor Bazarov写道:
Victor Bazarov wrote:

正确。你在哪里找到这个?
Correct. Where did you find this one?



我在gcc的STL中发现了同样的问题。确实sgi'的STL文档

定义了尺寸必须是整数类型的要求。


Jens

I found the same issue in gcc''s STL. Indeed sgi''s STL documentation
defines the requirement to be that Size must be an integral type.

Jens

Jens Theisen写道:
Jens Theisen wrote:

Victor Bazarov写道:
Victor Bazarov wrote:

>正确。你在哪里找到这个?
>Correct. Where did you find this one?



我在gcc的STL中发现了同样的问题。事实上,sgi'的STL文档

定义了Size必须是一个整数类型的要求。


I found the same issue in gcc''s STL. Indeed sgi''s STL documentation
defines the requirement to be that Size must be an integral type.



该标准现已存在(自1997年以来),因此任何C ++

标准库实现都不会使用本地OP暗示变量是

无法使用枚举。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问

The requirement now exists in the Standard (since 1997), so any C++
standard library implementation that doesn''t use a local variable is
not going to work with enums, as the OP hinted.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask