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

033-traits::constructの戻り値について #150

Open
ame24924 opened this issue Jan 9, 2020 · 1 comment
Open

033-traits::constructの戻り値について #150

ame24924 opened this issue Jan 9, 2020 · 1 comment

Comments

@ame24924
Copy link

ame24924 commented Jan 9, 2020

"033-vector-implementation"に関してです。
std::string * s = traits::construct( a, p, "hello") ;
と、traits::constructの戻り値を定義していますが、c++ referenceを見るとtraits::constructの戻り値はvoidですし、std::string *sと定義する必要はないのではないでしょうか?

@sylph01
Copy link
Contributor

sylph01 commented May 15, 2021

👍 本の表記のままではエラーを得ました。

再現コードは以下です:

#include "../all.h"

int main(){
  std::allocator<std::string> a;
  using traits = std::allocator_traits<decltype(a)>;
  std::string * p = traits::allocate(a, 1);
  std::string * s = traits::construct(a, p, "hello");
  // traits::construct(a, p, "hello");

  // std::cout << *p << std::endl;

  traits::destroy(a, s);
  //traits::destroy(a, p);

  traits::deallocate(a, p, 1);
}

エラーメッセージは以下:

$ g++ -std=c++17 -Wall -pedantic-errors allocator_traits_.cpp 
allocator_traits_.cpp: In function ‘int main()’:
allocator_traits_.cpp:7:38: error: void value not ignored as it ought to be
    7 |   std::string * s = traits::construct(a, p, "hello");
      |                     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~

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