Show a patch.

GET /api/patches/12301/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 12301,
    "url": "https://patchwork.libcamera.org/api/patches/12301/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/12301/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20210515040511.23294-4-laurent.pinchart@ideasonboard.com>",
    "date": "2021-05-15T04:05:10",
    "name": "[libcamera-devel,v2,3/4] libcamera: utils: enumerate: Use named fields for result",
    "commit_ref": null,
    "pull_url": null,
    "state": "rejected",
    "archived": false,
    "hash": "c14d21e8561cf2ff34d66987d793d00ba4cdb1e4",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": {
        "id": 14,
        "url": "https://patchwork.libcamera.org/api/users/14/?format=api",
        "username": "pinchartl",
        "first_name": "Laurent",
        "last_name": "Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "mbox": "https://patchwork.libcamera.org/patch/12301/mbox/",
    "series": [
        {
            "id": 2032,
            "url": "https://patchwork.libcamera.org/api/series/2032/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2032",
            "date": "2021-05-15T04:05:07",
            "name": "libcamera: Simplify range-based for loop counters",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/2032/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/12301/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/12301/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id E36E6C31F6\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 15 May 2021 04:05:31 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A190F6891C;\n\tSat, 15 May 2021 06:05:31 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B277A68923\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 15 May 2021 06:05:26 +0200 (CEST)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 679E08BA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 15 May 2021 06:05:26 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"YRJl16Bm\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1621051526;\n\tbh=xdyhj7jYUZd6VeeyYZ0TE83/w4PfET+8+wYL0cDkmIc=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=YRJl16BmNGD9dSw1nrbG7OuUL8Jz2xMudHXuk8pH9+XsYl6U2UodWBHBgR0ph3Ze2\n\tnFrIpGLeBxfA0/V7jSK3aGG+Ucz4Dp5gtm2tozevhS5UH1wblDTlM83zeG1iFs849B\n\tZNAA6VVJ21+8NhMwTUDn/PLgJtwneXJIH64vJtSc=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sat, 15 May 2021 07:05:10 +0300",
        "Message-Id": "<20210515040511.23294-4-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.28.1",
        "In-Reply-To": "<20210515040511.23294-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20210515040511.23294-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v2 3/4] libcamera: utils: enumerate: Use\n\tnamed fields for result",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Returning a pair of { index, value } from container enumeration is\nerror-prone, as the index and value can easily be swapped. Use a\nstructure with named index and value fields instead.\n\nThis will be squashed with \"libcamera: utils: Add enumerate view for\nrange-based for loops\" if accepted.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/internal/utils.h | 16 +++++++++++-----\n src/libcamera/utils.cpp            | 13 +++++++------\n test/utils.cpp                     | 24 ++++++++++++------------\n 3 files changed, 30 insertions(+), 23 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h\nindex 83dada7cc16c..5ea82e68a7a2 100644\n--- a/include/libcamera/internal/utils.h\n+++ b/include/libcamera/internal/utils.h\n@@ -16,7 +16,6 @@\n #include <string>\n #include <string.h>\n #include <sys/time.h>\n-#include <utility>\n #include <vector>\n \n #ifndef __DOXYGEN__\n@@ -237,12 +236,19 @@ namespace details {\n template<typename Base>\n class enumerate_iterator\n {\n-private:\n-\tusing base_reference = typename std::iterator_traits<Base>::reference;\n-\n public:\n \tusing difference_type = typename std::iterator_traits<Base>::difference_type;\n-\tusing value_type = std::pair<const difference_type, base_reference>;\n+\n+private:\n+\tusing base_reference = typename std::iterator_traits<Base>::reference;\n+\n+\tstruct result {\n+\t\tconst difference_type index;\n+\t\tbase_reference value;\n+\t};\n+\n+public:\n+\tusing value_type = result;\n \tusing pointer = value_type *;\n \tusing reference = value_type &;\n \tusing iterator_category = std::input_iterator_tag;\ndiff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\nindex ff9a5832b10e..b4b4180c1337 100644\n--- a/src/libcamera/utils.cpp\n+++ b/src/libcamera/utils.cpp\n@@ -481,20 +481,21 @@ std::string libcameraSourcePath()\n  * in their ability to replace for loops that require access to a loop counter.\n  * The enumerate() function solves this problem by wrapping the \\a iterable in\n  * an adapter that, when used as a range-expression, will provide iterators\n- * whose value_type is a pair of index and value reference.\n+ * whose value_type exposes both the element's value and its index.\n  *\n  * The iterable must support std::begin() and std::end(). This includes all\n  * containers provided by the standard C++ library, as well as C-style arrays.\n  *\n- * A typical usage pattern would use structured binding to store the index and\n- * value in two separate variables:\n+ * The iterator's value_type is a structure that aggregates the index and value\n+ * reference in two named members. The index is always const, and the value\n+ * reference is conditionally const depending on the iterable. A typical usage\n+ * pattern would be:\n  *\n  * \\code{.cpp}\n  * std::vector<int> values = ...;\n  *\n- * for (auto [index, value] : utils::enumerate(values)) {\n- * \t...\n- * }\n+ * for (const auto v : utils::enumerate(values))\n+ * \tstd::cout << \"- index \" << v.index << \", value \" << v.value << std::endl;\n  * \\endcode\n  *\n  * \\return A value of unspecified type that, when used in a range-based for\ndiff --git a/test/utils.cpp b/test/utils.cpp\nindex 7e24c71e4775..06ce5301a74e 100644\n--- a/test/utils.cpp\n+++ b/test/utils.cpp\n@@ -79,16 +79,16 @@ protected:\n \t\tstd::vector<int> integers{ 1, 2, 3, 4, 5 };\n \t\tint i = 0;\n \n-\t\tfor (auto [index, value] : utils::enumerate(integers)) {\n-\t\t\tif (index != i || value != i + 1) {\n+\t\tfor (const auto v : utils::enumerate(integers)) {\n+\t\t\tif (v.index != i || v.value != i + 1) {\n \t\t\t\tcerr << \"utils::enumerate(<vector>) test failed: i=\" << i\n-\t\t\t\t     << \", index=\" << index << \", value=\" << value\n-\t\t\t\t     << std::endl;\n+\t\t\t\t     << \", index=\" << v.index << \", value=\" << v.value\n+\t\t\t\t     << endl;\n \t\t\t\treturn TestFail;\n \t\t\t}\n \n \t\t\t/* Verify that we can modify the value. */\n-\t\t\t--value;\n+\t\t\t--v.value;\n \t\t\t++i;\n \t\t}\n \n@@ -100,10 +100,10 @@ protected:\n \t\tSpan<const int> span{ integers };\n \t\ti = 0;\n \n-\t\tfor (auto [index, value] : utils::enumerate(span)) {\n-\t\t\tif (index != i || value != i) {\n+\t\tfor (const auto v : utils::enumerate(span)) {\n+\t\t\tif (v.index != i || v.value != i) {\n \t\t\t\tcerr << \"utils::enumerate(<span>) test failed: i=\" << i\n-\t\t\t\t     << \", index=\" << index << \", value=\" << value\n+\t\t\t\t     << \", index=\" << v.index << \", value=\" << v.value\n \t\t\t\t     << std::endl;\n \t\t\t\treturn TestFail;\n \t\t\t}\n@@ -114,11 +114,11 @@ protected:\n \t\tconst int array[] = { 0, 2, 4, 6, 8 };\n \t\ti = 0;\n \n-\t\tfor (auto [index, value] : utils::enumerate(array)) {\n-\t\t\tif (index != i || value != i * 2) {\n+\t\tfor (const auto v : utils::enumerate(array)) {\n+\t\t\tif (v.index != i || v.value != i * 2) {\n \t\t\t\tcerr << \"utils::enumerate(<array>) test failed: i=\" << i\n-\t\t\t\t     << \", index=\" << index << \", value=\" << value\n-\t\t\t\t     << std::endl;\n+\t\t\t\t     << \", index=\" << v.index << \", value=\" << v.value\n+\t\t\t\t     << endl;\n \t\t\t\treturn TestFail;\n \t\t\t}\n \n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "3/4"
    ]
}