Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于测试mystl::vector<std::string> v3找不到可匹配的destroy的问题 #138

Open
wanfengcxz opened this issue Aug 27, 2023 · 1 comment

Comments

@wanfengcxz
Copy link

using std::string;
mystl::vector<string> v3;

如上代码所示,当定义v3变量时,编译器报错:

In template: call to function 'destroy' that is neither visible in the template definition nor found by argument-dependent lookup

即在如下位置:

destroy(&*first);

提示找不到destroy

template <class ForwardIter>
void destroy_cat(ForwardIter first, ForwardIter last, std::false_type)
{
  for (; first != last; ++first)
    destroy(&*first);
}

此处应该是因为编译找不到destroy函数的声明,因为destroy定义在后面。所以,我认为应该在这个函数前面加上一个声明,即如下所示:

template<class Ty>
void destroy(Ty *pointer);

template <class ForwardIter>
void destroy_cat(ForwardIter first, ForwardIter last, std::false_type)
{
  for (; first != last; ++first)
    destroy(&*first);
}

加上之后,编译器就不再报错了,也能运行了~
不知道这算不算一个bug。如果确实需要修复,能不能让我提个pr来修复一下(我会看一下pr规范的)

@wanfengcxz wanfengcxz changed the title 关于测试mystl::vector<std::string> v1找不到可匹配的destroy的问题 关于测试mystl::vector<std::string> v3找不到可匹配的destroy的问题 Aug 27, 2023
@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Oct 9, 2023

我认为析构单个对象的函数应该叫 destroy_at (我们可以引入新函数,然后弃用旧的析构单对象版本)。
另外应该用类似 std::addressof 的机制避免 ADL 和重载 operator& 的问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants