Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-120924

Initializing a QList with iterators of a std::range leads to warnings

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.5.2
    • None
    • MSVC 2022 (17.4)
    • Windows

    Description

      When I try to use QList constructor QList::QList(InputIterator first, InputIterator last) with the iterators of a range, I get

       

      warning: C4996: 'QList<Node>::const_iterator::operator T': Use operator* or operator-> rather than relying on the implicit conversion between a QList/QVector::const_iterator and a raw pointer
      

      Sample code:

       

      #include <ranges>
      #include <QDebug>
      struct Node
      {
      public:
         int m_Id;
         //...
      };
      auto convertToIdListView(const auto& arg)
      {
          auto fConvertToId = [](const Node& node)
              {
                  return node.m_Id;
              };
          auto idListView = std::views::transform(arg,fConvertToId);
          return idListView;
      }
      QList<int> convertToIdList(const QList<Node>& arg)
      {
          const auto idListView = convertToIdListView(arg);
          return {QList<int>{idListView.begin(), idListView.end()}};
      }
      int main(int argc, char *argv[])
      {
          QList<Node> nodeList{{.m_Id=1},{.m_Id=2},{.m_Id=5}};
          
          qDebug() << convertToIdList(nodeList);
      }
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            asperamanca Robert Schimkowitsch
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes