rajatjain1997 / thecodepad

Utterances on thecodepad
0 stars 0 forks source link

C++20 Concepts: The Definitive Guide - The Code Pad #2

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

C++20 Concepts: The Definitive Guide - The Code Pad

This tutorial introduces C++20 concepts as a way to type-constrain templates, provide saner overload resolution, and throw better error messages.

https://thecodepad.com/cpp/c20-concepts-the-definitive-guide/

GiovanniLR commented 2 years ago

Hello, nice overview. The "pythonic" string mul code needs a small fix though, probably something like: T mul(T a, int b) { std::string ret{std::move(a)}; ret.reserve(ret.length() *b); auto start_pos{ret.begin()}; auto end_pos{ret.end()}; for (int i=1; i<b; ++i) { std::copy(start_pos, end_pos, std::back_inserter(ret)); } return ret; }

rajatjain1997 commented 2 years ago

Yeah, that's right. I've made a change.