Bobinas P4G
  • Login
  • Public

    • Public
    • Groups
    • Popular
    • People

Conversation

Notices

  1. Bernie (codewiz@mstdn.io)'s status on Friday, 23-Jun-2023 20:47:18 UTC Bernie Bernie
    in reply to
    • Šimon Tóth

    @simontoth O have recently enabled C++20 on an embedded code add, but haven't tried ranges and views yet.

    How well do they perform on short sequences? Would code size increase compared to hand-coded loops?

    And... do they work with fixed-size containers without heap allocations?

    In conversation Friday, 23-Jun-2023 20:47:18 UTC from mstdn.io permalink
    • Šimon Tóth (simontoth@hachyderm.io)'s status on Friday, 23-Jun-2023 20:47:19 UTC Šimon Tóth Šimon Tóth

      When working with C++20 views, creating functions that encapsulate complex view compositions might be tempting.

      However, that will very likely lead to unnecessary data copies. Instead, consider compositing views as inline constexpr variables.

      Compiler Explorer link: https://compiler-explorer.com/z/vG4hhe77h

      #cpp #cplusplus #coding #programming #dailybiteofcpp

      In conversation Friday, 23-Jun-2023 20:47:19 UTC permalink

      Attachments


      1. https://media.hachyderm.io/media_attachments/files/110/572/132/460/711/982/original/6dba6a91bb46484c.png
      2. Compiler Explorer - C++
        from Matt Godbolt
        constexpr inline auto trim_front = std::views::drop_while([](int c) { return std::isspace(c); }); constexpr inline auto trim_back = std::views::reverse | trim_front | std::views::reverse; constexpr inline auto trim_space = trim_back | trim_front; int main() { std::string str = " abc \t"; // Compose the view with data auto lazy_trimmed = str | trim_space; // Generate the output (before C++23 std::ranges::to) std::string out(lazy_trimmed.begin(), lazy_trimmed.end()); // out == "abc" std::cout << "out == " << std::quoted(out) << "\n"; }

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • Privacy
  • Source
  • Version
  • Contact

Bobinas P4G is a social network. It runs on GNU social, version 2.0.1-beta0, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All Bobinas P4G content and data are available under the Creative Commons Attribution 3.0 license.