News for hackers. Stuff that matters.
Re:C++20 Concepts: The Definitive Guide by creativeCak3 on Sunday August 22, 2021 @05:59PM (#28270069)
Am I going insane or does the following does NOT work(?):

<code> template<typename T> T mul(T a, T b) { return ab; }

template<typename T> T mul(T a, int b) { std::string ret_val{std::move(a)}; a.reserve(a.length() b); auto start_pos{a.begin()}; auto end_pos{a.end()}; for(int i = 0; i < b; i++) { std::copy(start_pos, end_pos, std::back_inserter(a)); } return ret_val; } </code>

I knew it looked odd to me for some reason...I had to re-write it as follows:

<code> template<typename T> T mul(T a, T b) { return ab; }

template<typename T> T mul(T a, int b) { std::string ret_val{}; ret_val.reserve(a.length() b); auto start_pos{a.begin()}; auto end_pos{a.end()}; for(int i = 0; i < b; i++) { std::copy(start_pos, end_pos, std::back_inserter(ret_val)); } return ret_val; } </code>

Did I miss something??

Re:C++20 Concepts: The Definitive Guide by vips7L on Sunday August 22, 2021 @11:27PM (#28272049)
Four spaces before each line will format your code so other people can read it.
Re:C++20 Concepts: The Definitive Guide by steveklabnik on Sunday August 22, 2021 @11:35PM (#28272096)
You only need two on Hacker News, not four. https://news.ycombinator.com/formatdoc
Re:C++20 Concepts: The Definitive Guide by vips7L on Monday August 23, 2021 @06:48AM (#28274114)
TIL thanks.