Envoltorio const para el iterador -- ++ campo con c++11 campo con iterator campo con template-meta-programming camp codereview Relacionados El problema

Const wrapper for iterator


4
vote

problema

Español

Editar : agregó una aclaración de por qué quiero esto, y actualiza el código ya que no tengo ninguna respuesta todavía

Tengo una clase similar a la matriz C ++ 11 que (puede ser) una envoltura alrededor de un iterador de acceso aleatorio. Acceso basado en el índice y .begin() / .end()3 puede pasar al iterador, pero hay un poco de complicación cuando el objeto es 9988777665544334 : < / p>

      template<class Size, typename DataIterator>     class Storage : public Size {         DataIterator iterator;     public:         Storage(const DataIterator &iterator, const Size &size) : Size(size), iterator(iterator) {}                  auto operator[](index_t i)                 -> decltype(iterator[i]) {             return iterator[i];         }         auto operator[](index_t i) const                 -> MakeConst<decltype(iterator[i])> {             return iterator[i];         }                  DataIterator begin() {return iterator;}         ConstWrapper<DataIterator> begin() const {return iterator;}         DataIterator end() {return iterator + this->size();}         ConstWrapper<DataIterator> end() const {return iterator + this->size();}     };  

Si simplemente devolvemos DataIterator desde el const y .end() , luego las personas que sostienen un < CÓDIGO> 99887766555443310 (¡incorrectamente!) Podría modificar la matriz a través de ese iterador.

contenedores como {% extends 'directory/base.html' %} {% block content %} <div id="tabs"> <ul id="gaugeList"> {% for workgroup in context['workgroup_list'] %} <li><h3> <a class="gaugeCell" id="{{ workgroup.shorthand }}" href="#tabs-{{ workgroup.shorthand }}"></a> </h3></li> {% endfor %} </ul> <div id="gridBox" class="scrollable"> <table id="connectionGrid" class="tablesorter"> <thead> <tr> <th>Type</th> <th>Computer</th> <th>Workgroup</th> <th>C: Drive %</th> <th></th> <th></th> <th></th> <th class="clearall button" onclick="hideRows()">Clear All</th> <th onclick="collapseListener()" id="collapserows" class="collapseall button">Collapse All</th> </tr> </thead> <tbody id="connectionBody"> {% for computer in context['computer_list'] %} {% if (computer.visible == True or current_user.is_admin) and computer.active_drive is not none %} <tr id="{{computer.name}}" class="parent"> <td rowspan="1" class="type"> <a href="#" class="toggle">{{ computer.station_type if computer.station_type else 'Enter Data'}}</a> </td> <td class="name"> <a href="#" id="name" class="toggle">{{computer.name}}</a> </td> <td class="workgroup"> <a href="#" id="{{computer.name}}_workgroup" class="innerworkgroup toggle">{{computer.active_drive.workgroup.shorthand}}</a> </td> <td class="util"> <a href="#" class="toggle" id="{{computer.name}}_util">{{ computer.active_drive.percentage_full if computer.active_drive.percentage_full else 'Check Service'}}</a> </td> <td> <a id="{{computer.name}}_Users" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMUsers" target="_blank">Users</a> </td> <td> <a id="{{computer.name}}_Projects" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMProjects" target="_blank">Projects</a> </td> <td> <a id="{{computer.name}}_attic" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name}}/MMAttic" target="_blank">Attic</a> </td> <td> <a id="{{computer.name}}_pcusers" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMPCUsers" target="_blank">Desktops</a> </td> <td> <img src="{{url_for('static',filename='images/refresh.png')}}" title="Service restart may take up to a minute" id="{{computer.name}}_refresh" class="pclinks_{{computer.name}}" onclick="refresh(this)" target="_blank"> </img> </td> <tr class="tablesorter-childRow"> <td class="label dualboot topitem" colspan="1">Dual Boot</td> <td class="info dualboot topitem" colspan="1" > {{ 'Yes' if computer.dual_boot == True else 'No' }} </td> <td class="label topitem" colspan="3" style="text-align:center;">{{computer.active_drive.image_version}}</td> <td class="label topitem" colspan="2">Media Composer</td> <td class="info topitem" colspan="2">{{computer.active_drive.media_composer_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" colspan="1">Network Name</td> <td class="info" colspan="1" id="{{computer.name}}_network">{{ computer.active_drive.name }}</td> <td class="label">Model</td> <td class="info" colspan="2"> {{ computer.model if computer.model else 'Check Service' }}</td> <td class="label" colspan="2">Interplay Access</td> <td class="info" colspan="2">{{computer.active_drive.access_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label">Room</td> <td class="info" colspan="1"> {% if computer.room %} {{ computer.room }} ({{computer.room.description}}) {% else %} Enter Data {% endif %} </td> <td class="label" colspan="1">Edit Service</td> <td class="info" colspan="2">{{computer.active_drive.edit_service_version}}</td> <td class="label" colspan="2">Media Indexer</td> <td class="info " colspan="2">{{computer.active_drive.indexer_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" colspan="1">Phone</td> <td class="info" colspan="1"> {{ computer.room.phone_numbers if computer.room.phone_numbers else 'Enter Data'}}</td> <td class="label ">Boot Time</td> <td class="info " colspan="2" id="{{computer.name}}_boot"> {% if computer.online == false %} Offline {% else %} {{ computer.active_drive.boot_time if computer.active_drive.boot_time else 'Check Service' }} {% endif %} </td> <td class="label" colspan="2">Transfer Client</td> <td class="info" colspan="2">{{computer.active_drive.transfer_client_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" id="intercomlabel" colspan="1">Intercom</td> <td class="info" colspan="1"> {{ computer.room.intercom_numbers if computer.room.intercom_numbers else 'Enter Data' }} </td> <td class="label" colspan="1">Checked-In</td> <td class="info checkin" colspan="2" id="{{computer.name}}_checked_in"> {{ computer.active_drive.last_checked_in if computer.active_drive.last_checked_in else 'Check Service' }} </td> <td class="label" colspan="2">Avid ISIS Client</td> <td class="info" colspan="2">{{computer.active_drive.isis_client_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label">Notes</td> <td class="info" colspan="1">{{ computer.notes if computer.notes else ''}}</td> <td class="label">Swing Date</td> <td class="info" colspan="2">{{ computer.active_drive.last_changed_workgroup }}</td> <td class="label" colspan="2">Nvidia Driver</td> <td class="info " colspan="2">{{computer.active_drive.graphics_driver_version}}</td> </tr> {% endif %} {% endfor %} </tbody> </table> </div> <div id="bottom" class="bottom"> {% for workgroup in context['workgroup_list'] %} <a href="#" id="{{workgroup.shorthand}}" class="show_{{workgroup}}"> {{ workgroup.shorthand }} </a> {% endfor %} </div> </div> {% endblock %}1 tiene dos iteradores separados ( 99887766555443312 y {% extends 'directory/base.html' %} {% block content %} <div id="tabs"> <ul id="gaugeList"> {% for workgroup in context['workgroup_list'] %} <li><h3> <a class="gaugeCell" id="{{ workgroup.shorthand }}" href="#tabs-{{ workgroup.shorthand }}"></a> </h3></li> {% endfor %} </ul> <div id="gridBox" class="scrollable"> <table id="connectionGrid" class="tablesorter"> <thead> <tr> <th>Type</th> <th>Computer</th> <th>Workgroup</th> <th>C: Drive %</th> <th></th> <th></th> <th></th> <th class="clearall button" onclick="hideRows()">Clear All</th> <th onclick="collapseListener()" id="collapserows" class="collapseall button">Collapse All</th> </tr> </thead> <tbody id="connectionBody"> {% for computer in context['computer_list'] %} {% if (computer.visible == True or current_user.is_admin) and computer.active_drive is not none %} <tr id="{{computer.name}}" class="parent"> <td rowspan="1" class="type"> <a href="#" class="toggle">{{ computer.station_type if computer.station_type else 'Enter Data'}}</a> </td> <td class="name"> <a href="#" id="name" class="toggle">{{computer.name}}</a> </td> <td class="workgroup"> <a href="#" id="{{computer.name}}_workgroup" class="innerworkgroup toggle">{{computer.active_drive.workgroup.shorthand}}</a> </td> <td class="util"> <a href="#" class="toggle" id="{{computer.name}}_util">{{ computer.active_drive.percentage_full if computer.active_drive.percentage_full else 'Check Service'}}</a> </td> <td> <a id="{{computer.name}}_Users" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMUsers" target="_blank">Users</a> </td> <td> <a id="{{computer.name}}_Projects" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMProjects" target="_blank">Projects</a> </td> <td> <a id="{{computer.name}}_attic" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name}}/MMAttic" target="_blank">Attic</a> </td> <td> <a id="{{computer.name}}_pcusers" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMPCUsers" target="_blank">Desktops</a> </td> <td> <img src="{{url_for('static',filename='images/refresh.png')}}" title="Service restart may take up to a minute" id="{{computer.name}}_refresh" class="pclinks_{{computer.name}}" onclick="refresh(this)" target="_blank"> </img> </td> <tr class="tablesorter-childRow"> <td class="label dualboot topitem" colspan="1">Dual Boot</td> <td class="info dualboot topitem" colspan="1" > {{ 'Yes' if computer.dual_boot == True else 'No' }} </td> <td class="label topitem" colspan="3" style="text-align:center;">{{computer.active_drive.image_version}}</td> <td class="label topitem" colspan="2">Media Composer</td> <td class="info topitem" colspan="2">{{computer.active_drive.media_composer_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" colspan="1">Network Name</td> <td class="info" colspan="1" id="{{computer.name}}_network">{{ computer.active_drive.name }}</td> <td class="label">Model</td> <td class="info" colspan="2"> {{ computer.model if computer.model else 'Check Service' }}</td> <td class="label" colspan="2">Interplay Access</td> <td class="info" colspan="2">{{computer.active_drive.access_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label">Room</td> <td class="info" colspan="1"> {% if computer.room %} {{ computer.room }} ({{computer.room.description}}) {% else %} Enter Data {% endif %} </td> <td class="label" colspan="1">Edit Service</td> <td class="info" colspan="2">{{computer.active_drive.edit_service_version}}</td> <td class="label" colspan="2">Media Indexer</td> <td class="info " colspan="2">{{computer.active_drive.indexer_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" colspan="1">Phone</td> <td class="info" colspan="1"> {{ computer.room.phone_numbers if computer.room.phone_numbers else 'Enter Data'}}</td> <td class="label ">Boot Time</td> <td class="info " colspan="2" id="{{computer.name}}_boot"> {% if computer.online == false %} Offline {% else %} {{ computer.active_drive.boot_time if computer.active_drive.boot_time else 'Check Service' }} {% endif %} </td> <td class="label" colspan="2">Transfer Client</td> <td class="info" colspan="2">{{computer.active_drive.transfer_client_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" id="intercomlabel" colspan="1">Intercom</td> <td class="info" colspan="1"> {{ computer.room.intercom_numbers if computer.room.intercom_numbers else 'Enter Data' }} </td> <td class="label" colspan="1">Checked-In</td> <td class="info checkin" colspan="2" id="{{computer.name}}_checked_in"> {{ computer.active_drive.last_checked_in if computer.active_drive.last_checked_in else 'Check Service' }} </td> <td class="label" colspan="2">Avid ISIS Client</td> <td class="info" colspan="2">{{computer.active_drive.isis_client_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label">Notes</td> <td class="info" colspan="1">{{ computer.notes if computer.notes else ''}}</td> <td class="label">Swing Date</td> <td class="info" colspan="2">{{ computer.active_drive.last_changed_workgroup }}</td> <td class="label" colspan="2">Nvidia Driver</td> <td class="info " colspan="2">{{computer.active_drive.graphics_driver_version}}</td> </tr> {% endif %} {% endfor %} </tbody> </table> </div> <div id="bottom" class="bottom"> {% for workgroup in context['workgroup_list'] %} <a href="#" id="{{workgroup.shorthand}}" class="show_{{workgroup}}"> {{ workgroup.shorthand }} </a> {% endfor %} </div> </div> {% endblock %}3 ), pero nuestro 99887776655443314 sólo tiene El lectura-escribe uno, por lo que sintetizamos uno usando {% extends 'directory/base.html' %} {% block content %} <div id="tabs"> <ul id="gaugeList"> {% for workgroup in context['workgroup_list'] %} <li><h3> <a class="gaugeCell" id="{{ workgroup.shorthand }}" href="#tabs-{{ workgroup.shorthand }}"></a> </h3></li> {% endfor %} </ul> <div id="gridBox" class="scrollable"> <table id="connectionGrid" class="tablesorter"> <thead> <tr> <th>Type</th> <th>Computer</th> <th>Workgroup</th> <th>C: Drive %</th> <th></th> <th></th> <th></th> <th class="clearall button" onclick="hideRows()">Clear All</th> <th onclick="collapseListener()" id="collapserows" class="collapseall button">Collapse All</th> </tr> </thead> <tbody id="connectionBody"> {% for computer in context['computer_list'] %} {% if (computer.visible == True or current_user.is_admin) and computer.active_drive is not none %} <tr id="{{computer.name}}" class="parent"> <td rowspan="1" class="type"> <a href="#" class="toggle">{{ computer.station_type if computer.station_type else 'Enter Data'}}</a> </td> <td class="name"> <a href="#" id="name" class="toggle">{{computer.name}}</a> </td> <td class="workgroup"> <a href="#" id="{{computer.name}}_workgroup" class="innerworkgroup toggle">{{computer.active_drive.workgroup.shorthand}}</a> </td> <td class="util"> <a href="#" class="toggle" id="{{computer.name}}_util">{{ computer.active_drive.percentage_full if computer.active_drive.percentage_full else 'Check Service'}}</a> </td> <td> <a id="{{computer.name}}_Users" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMUsers" target="_blank">Users</a> </td> <td> <a id="{{computer.name}}_Projects" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMProjects" target="_blank">Projects</a> </td> <td> <a id="{{computer.name}}_attic" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name}}/MMAttic" target="_blank">Attic</a> </td> <td> <a id="{{computer.name}}_pcusers" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMPCUsers" target="_blank">Desktops</a> </td> <td> <img src="{{url_for('static',filename='images/refresh.png')}}" title="Service restart may take up to a minute" id="{{computer.name}}_refresh" class="pclinks_{{computer.name}}" onclick="refresh(this)" target="_blank"> </img> </td> <tr class="tablesorter-childRow"> <td class="label dualboot topitem" colspan="1">Dual Boot</td> <td class="info dualboot topitem" colspan="1" > {{ 'Yes' if computer.dual_boot == True else 'No' }} </td> <td class="label topitem" colspan="3" style="text-align:center;">{{computer.active_drive.image_version}}</td> <td class="label topitem" colspan="2">Media Composer</td> <td class="info topitem" colspan="2">{{computer.active_drive.media_composer_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" colspan="1">Network Name</td> <td class="info" colspan="1" id="{{computer.name}}_network">{{ computer.active_drive.name }}</td> <td class="label">Model</td> <td class="info" colspan="2"> {{ computer.model if computer.model else 'Check Service' }}</td> <td class="label" colspan="2">Interplay Access</td> <td class="info" colspan="2">{{computer.active_drive.access_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label">Room</td> <td class="info" colspan="1"> {% if computer.room %} {{ computer.room }} ({{computer.room.description}}) {% else %} Enter Data {% endif %} </td> <td class="label" colspan="1">Edit Service</td> <td class="info" colspan="2">{{computer.active_drive.edit_service_version}}</td> <td class="label" colspan="2">Media Indexer</td> <td class="info " colspan="2">{{computer.active_drive.indexer_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" colspan="1">Phone</td> <td class="info" colspan="1"> {{ computer.room.phone_numbers if computer.room.phone_numbers else 'Enter Data'}}</td> <td class="label ">Boot Time</td> <td class="info " colspan="2" id="{{computer.name}}_boot"> {% if computer.online == false %} Offline {% else %} {{ computer.active_drive.boot_time if computer.active_drive.boot_time else 'Check Service' }} {% endif %} </td> <td class="label" colspan="2">Transfer Client</td> <td class="info" colspan="2">{{computer.active_drive.transfer_client_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" id="intercomlabel" colspan="1">Intercom</td> <td class="info" colspan="1"> {{ computer.room.intercom_numbers if computer.room.intercom_numbers else 'Enter Data' }} </td> <td class="label" colspan="1">Checked-In</td> <td class="info checkin" colspan="2" id="{{computer.name}}_checked_in"> {{ computer.active_drive.last_checked_in if computer.active_drive.last_checked_in else 'Check Service' }} </td> <td class="label" colspan="2">Avid ISIS Client</td> <td class="info" colspan="2">{{computer.active_drive.isis_client_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label">Notes</td> <td class="info" colspan="1">{{ computer.notes if computer.notes else ''}}</td> <td class="label">Swing Date</td> <td class="info" colspan="2">{{ computer.active_drive.last_changed_workgroup }}</td> <td class="label" colspan="2">Nvidia Driver</td> <td class="info " colspan="2">{{computer.active_drive.graphics_driver_version}}</td> </tr> {% endif %} {% endfor %} </tbody> </table> </div> <div id="bottom" class="bottom"> {% for workgroup in context['workgroup_list'] %} <a href="#" id="{{workgroup.shorthand}}" class="show_{{workgroup}}"> {{ workgroup.shorthand }} </a> {% endfor %} </div> </div> {% endblock %}5 :

  {% extends 'directory/base.html' %}  {% block content %}  <div id="tabs">     <ul id="gaugeList">         {% for workgroup in context['workgroup_list'] %}         <li><h3>         <a class="gaugeCell" id="{{ workgroup.shorthand }}" href="#tabs-{{ workgroup.shorthand }}"></a>         </h3></li>         {% endfor %}     </ul>     <div id="gridBox" class="scrollable">         <table id="connectionGrid" class="tablesorter">             <thead>                 <tr>                     <th>Type</th>                     <th>Computer</th>                     <th>Workgroup</th>                     <th>C: Drive %</th>                     <th></th>                     <th></th>                     <th></th>                     <th class="clearall button" onclick="hideRows()">Clear All</th>                     <th onclick="collapseListener()" id="collapserows" class="collapseall button">Collapse All</th>                 </tr>             </thead>             <tbody id="connectionBody">                 {% for computer in context['computer_list'] %}                  {% if (computer.visible == True or current_user.is_admin) and computer.active_drive is not none %}                 <tr id="{{computer.name}}" class="parent">                     <td rowspan="1" class="type">                         <a href="#" class="toggle">{{ computer.station_type if computer.station_type else 'Enter Data'}}</a>                     </td>                     <td class="name">                         <a href="#" id="name" class="toggle">{{computer.name}}</a>                     </td>                     <td class="workgroup">                         <a href="#" id="{{computer.name}}_workgroup" class="innerworkgroup toggle">{{computer.active_drive.workgroup.shorthand}}</a>                     </td>                     <td class="util">                         <a href="#" class="toggle" id="{{computer.name}}_util">{{ computer.active_drive.percentage_full if computer.active_drive.percentage_full else 'Check Service'}}</a>                     </td>                     <td>                         <a id="{{computer.name}}_Users" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMUsers" target="_blank">Users</a>                     </td>                     <td>                         <a id="{{computer.name}}_Projects" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMProjects" target="_blank">Projects</a>                     </td>                     <td>                         <a id="{{computer.name}}_attic" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name}}/MMAttic" target="_blank">Attic</a>                     </td>                     <td>                         <a id="{{computer.name}}_pcusers" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMPCUsers" target="_blank">Desktops</a>                     </td>                     <td>                         <img src="{{url_for('static',filename='images/refresh.png')}}" title="Service restart may take up to a minute" id="{{computer.name}}_refresh" class="pclinks_{{computer.name}}" onclick="refresh(this)" target="_blank">                         </img>                     </td>                     <tr class="tablesorter-childRow">                         <td class="label dualboot topitem" colspan="1">Dual Boot</td>                         <td class="info dualboot topitem" colspan="1" >                             {{ 'Yes' if computer.dual_boot == True else 'No' }}                         </td>                          <td class="label topitem" colspan="3" style="text-align:center;">{{computer.active_drive.image_version}}</td>                          <td class="label topitem" colspan="2">Media Composer</td>                         <td class="info topitem" colspan="2">{{computer.active_drive.media_composer_version}}</td>                     </tr>                     <tr class="tablesorter-childRow">                         <td class="label" colspan="1">Network Name</td>                         <td class="info" colspan="1" id="{{computer.name}}_network">{{ computer.active_drive.name }}</td>                          <td class="label">Model</td>                         <td class="info" colspan="2">                             {{ computer.model if computer.model else 'Check Service' }}</td>                         <td class="label" colspan="2">Interplay Access</td>                         <td class="info" colspan="2">{{computer.active_drive.access_version}}</td>                     </tr>                     <tr class="tablesorter-childRow">                         <td class="label">Room</td>                         <td class="info" colspan="1">                             {% if computer.room %} {{ computer.room }} ({{computer.room.description}}) {% else %} Enter Data {% endif %}                         </td>                          <td class="label" colspan="1">Edit Service</td>                         <td class="info" colspan="2">{{computer.active_drive.edit_service_version}}</td>                         <td class="label" colspan="2">Media Indexer</td>                         <td class="info " colspan="2">{{computer.active_drive.indexer_version}}</td>                     </tr>                     <tr class="tablesorter-childRow">                         <td class="label" colspan="1">Phone</td>                         <td class="info" colspan="1">                             {{ computer.room.phone_numbers if computer.room.phone_numbers else 'Enter Data'}}</td>                          <td class="label ">Boot Time</td>                         <td class="info " colspan="2" id="{{computer.name}}_boot">                             {% if computer.online == false %} Offline {% else %} {{ computer.active_drive.boot_time if computer.active_drive.boot_time else 'Check Service' }} {% endif %}                         </td>                          <td class="label" colspan="2">Transfer Client</td>                         <td class="info" colspan="2">{{computer.active_drive.transfer_client_version}}</td>                     </tr>                     <tr class="tablesorter-childRow">                         <td class="label" id="intercomlabel" colspan="1">Intercom</td>                         <td class="info" colspan="1">                             {{ computer.room.intercom_numbers if computer.room.intercom_numbers else 'Enter Data' }}                         </td>                         <td class="label" colspan="1">Checked-In</td>                         <td class="info checkin" colspan="2" id="{{computer.name}}_checked_in">                             {{ computer.active_drive.last_checked_in if computer.active_drive.last_checked_in else 'Check Service' }}                         </td>                         <td class="label" colspan="2">Avid ISIS Client</td>                         <td class="info" colspan="2">{{computer.active_drive.isis_client_version}}</td>                     </tr>                     <tr class="tablesorter-childRow">                         <td class="label">Notes</td>                         <td class="info" colspan="1">{{ computer.notes if computer.notes else ''}}</td>                         <td class="label">Swing Date</td>                          <td class="info" colspan="2">{{ computer.active_drive.last_changed_workgroup }}</td>                          <td class="label" colspan="2">Nvidia Driver</td>                         <td class="info " colspan="2">{{computer.active_drive.graphics_driver_version}}</td>                    </tr>                  {% endif %}                  {% endfor %}             </tbody>         </table>      </div>      <div id="bottom" class="bottom">         {% for workgroup in context['workgroup_list'] %}         <a href="#" id="{{workgroup.shorthand}}" class="show_{{workgroup}}"> {{ workgroup.shorthand }} </a> {% endfor %}     </div> </div> {% endblock %}6  

La implementación reenvía todos los métodos relevantes, y tiene una especialización para {% extends 'directory/base.html' %} {% block content %} <div id="tabs"> <ul id="gaugeList"> {% for workgroup in context['workgroup_list'] %} <li><h3> <a class="gaugeCell" id="{{ workgroup.shorthand }}" href="#tabs-{{ workgroup.shorthand }}"></a> </h3></li> {% endfor %} </ul> <div id="gridBox" class="scrollable"> <table id="connectionGrid" class="tablesorter"> <thead> <tr> <th>Type</th> <th>Computer</th> <th>Workgroup</th> <th>C: Drive %</th> <th></th> <th></th> <th></th> <th class="clearall button" onclick="hideRows()">Clear All</th> <th onclick="collapseListener()" id="collapserows" class="collapseall button">Collapse All</th> </tr> </thead> <tbody id="connectionBody"> {% for computer in context['computer_list'] %} {% if (computer.visible == True or current_user.is_admin) and computer.active_drive is not none %} <tr id="{{computer.name}}" class="parent"> <td rowspan="1" class="type"> <a href="#" class="toggle">{{ computer.station_type if computer.station_type else 'Enter Data'}}</a> </td> <td class="name"> <a href="#" id="name" class="toggle">{{computer.name}}</a> </td> <td class="workgroup"> <a href="#" id="{{computer.name}}_workgroup" class="innerworkgroup toggle">{{computer.active_drive.workgroup.shorthand}}</a> </td> <td class="util"> <a href="#" class="toggle" id="{{computer.name}}_util">{{ computer.active_drive.percentage_full if computer.active_drive.percentage_full else 'Check Service'}}</a> </td> <td> <a id="{{computer.name}}_Users" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMUsers" target="_blank">Users</a> </td> <td> <a id="{{computer.name}}_Projects" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMProjects" target="_blank">Projects</a> </td> <td> <a id="{{computer.name}}_attic" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name}}/MMAttic" target="_blank">Attic</a> </td> <td> <a id="{{computer.name}}_pcusers" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMPCUsers" target="_blank">Desktops</a> </td> <td> <img src="{{url_for('static',filename='images/refresh.png')}}" title="Service restart may take up to a minute" id="{{computer.name}}_refresh" class="pclinks_{{computer.name}}" onclick="refresh(this)" target="_blank"> </img> </td> <tr class="tablesorter-childRow"> <td class="label dualboot topitem" colspan="1">Dual Boot</td> <td class="info dualboot topitem" colspan="1" > {{ 'Yes' if computer.dual_boot == True else 'No' }} </td> <td class="label topitem" colspan="3" style="text-align:center;">{{computer.active_drive.image_version}}</td> <td class="label topitem" colspan="2">Media Composer</td> <td class="info topitem" colspan="2">{{computer.active_drive.media_composer_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" colspan="1">Network Name</td> <td class="info" colspan="1" id="{{computer.name}}_network">{{ computer.active_drive.name }}</td> <td class="label">Model</td> <td class="info" colspan="2"> {{ computer.model if computer.model else 'Check Service' }}</td> <td class="label" colspan="2">Interplay Access</td> <td class="info" colspan="2">{{computer.active_drive.access_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label">Room</td> <td class="info" colspan="1"> {% if computer.room %} {{ computer.room }} ({{computer.room.description}}) {% else %} Enter Data {% endif %} </td> <td class="label" colspan="1">Edit Service</td> <td class="info" colspan="2">{{computer.active_drive.edit_service_version}}</td> <td class="label" colspan="2">Media Indexer</td> <td class="info " colspan="2">{{computer.active_drive.indexer_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" colspan="1">Phone</td> <td class="info" colspan="1"> {{ computer.room.phone_numbers if computer.room.phone_numbers else 'Enter Data'}}</td> <td class="label ">Boot Time</td> <td class="info " colspan="2" id="{{computer.name}}_boot"> {% if computer.online == false %} Offline {% else %} {{ computer.active_drive.boot_time if computer.active_drive.boot_time else 'Check Service' }} {% endif %} </td> <td class="label" colspan="2">Transfer Client</td> <td class="info" colspan="2">{{computer.active_drive.transfer_client_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" id="intercomlabel" colspan="1">Intercom</td> <td class="info" colspan="1"> {{ computer.room.intercom_numbers if computer.room.intercom_numbers else 'Enter Data' }} </td> <td class="label" colspan="1">Checked-In</td> <td class="info checkin" colspan="2" id="{{computer.name}}_checked_in"> {{ computer.active_drive.last_checked_in if computer.active_drive.last_checked_in else 'Check Service' }} </td> <td class="label" colspan="2">Avid ISIS Client</td> <td class="info" colspan="2">{{computer.active_drive.isis_client_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label">Notes</td> <td class="info" colspan="1">{{ computer.notes if computer.notes else ''}}</td> <td class="label">Swing Date</td> <td class="info" colspan="2">{{ computer.active_drive.last_changed_workgroup }}</td> <td class="label" colspan="2">Nvidia Driver</td> <td class="info " colspan="2">{{computer.active_drive.graphics_driver_version}}</td> </tr> {% endif %} {% endfor %} </tbody> </table> </div> <div id="bottom" class="bottom"> {% for workgroup in context['workgroup_list'] %} <a href="#" id="{{workgroup.shorthand}}" class="show_{{workgroup}}"> {{ workgroup.shorthand }} </a> {% endfor %} </div> </div> {% endblock %}7 para que no pueda envolverse.

Una parte clave es {% extends 'directory/base.html' %} {% block content %} <div id="tabs"> <ul id="gaugeList"> {% for workgroup in context['workgroup_list'] %} <li><h3> <a class="gaugeCell" id="{{ workgroup.shorthand }}" href="#tabs-{{ workgroup.shorthand }}"></a> </h3></li> {% endfor %} </ul> <div id="gridBox" class="scrollable"> <table id="connectionGrid" class="tablesorter"> <thead> <tr> <th>Type</th> <th>Computer</th> <th>Workgroup</th> <th>C: Drive %</th> <th></th> <th></th> <th></th> <th class="clearall button" onclick="hideRows()">Clear All</th> <th onclick="collapseListener()" id="collapserows" class="collapseall button">Collapse All</th> </tr> </thead> <tbody id="connectionBody"> {% for computer in context['computer_list'] %} {% if (computer.visible == True or current_user.is_admin) and computer.active_drive is not none %} <tr id="{{computer.name}}" class="parent"> <td rowspan="1" class="type"> <a href="#" class="toggle">{{ computer.station_type if computer.station_type else 'Enter Data'}}</a> </td> <td class="name"> <a href="#" id="name" class="toggle">{{computer.name}}</a> </td> <td class="workgroup"> <a href="#" id="{{computer.name}}_workgroup" class="innerworkgroup toggle">{{computer.active_drive.workgroup.shorthand}}</a> </td> <td class="util"> <a href="#" class="toggle" id="{{computer.name}}_util">{{ computer.active_drive.percentage_full if computer.active_drive.percentage_full else 'Check Service'}}</a> </td> <td> <a id="{{computer.name}}_Users" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMUsers" target="_blank">Users</a> </td> <td> <a id="{{computer.name}}_Projects" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMProjects" target="_blank">Projects</a> </td> <td> <a id="{{computer.name}}_attic" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name}}/MMAttic" target="_blank">Attic</a> </td> <td> <a id="{{computer.name}}_pcusers" class="enabled_link pclinks_{{computer.name}}" href="file://///{{ computer.active_drive.name }}/MMPCUsers" target="_blank">Desktops</a> </td> <td> <img src="{{url_for('static',filename='images/refresh.png')}}" title="Service restart may take up to a minute" id="{{computer.name}}_refresh" class="pclinks_{{computer.name}}" onclick="refresh(this)" target="_blank"> </img> </td> <tr class="tablesorter-childRow"> <td class="label dualboot topitem" colspan="1">Dual Boot</td> <td class="info dualboot topitem" colspan="1" > {{ 'Yes' if computer.dual_boot == True else 'No' }} </td> <td class="label topitem" colspan="3" style="text-align:center;">{{computer.active_drive.image_version}}</td> <td class="label topitem" colspan="2">Media Composer</td> <td class="info topitem" colspan="2">{{computer.active_drive.media_composer_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" colspan="1">Network Name</td> <td class="info" colspan="1" id="{{computer.name}}_network">{{ computer.active_drive.name }}</td> <td class="label">Model</td> <td class="info" colspan="2"> {{ computer.model if computer.model else 'Check Service' }}</td> <td class="label" colspan="2">Interplay Access</td> <td class="info" colspan="2">{{computer.active_drive.access_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label">Room</td> <td class="info" colspan="1"> {% if computer.room %} {{ computer.room }} ({{computer.room.description}}) {% else %} Enter Data {% endif %} </td> <td class="label" colspan="1">Edit Service</td> <td class="info" colspan="2">{{computer.active_drive.edit_service_version}}</td> <td class="label" colspan="2">Media Indexer</td> <td class="info " colspan="2">{{computer.active_drive.indexer_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" colspan="1">Phone</td> <td class="info" colspan="1"> {{ computer.room.phone_numbers if computer.room.phone_numbers else 'Enter Data'}}</td> <td class="label ">Boot Time</td> <td class="info " colspan="2" id="{{computer.name}}_boot"> {% if computer.online == false %} Offline {% else %} {{ computer.active_drive.boot_time if computer.active_drive.boot_time else 'Check Service' }} {% endif %} </td> <td class="label" colspan="2">Transfer Client</td> <td class="info" colspan="2">{{computer.active_drive.transfer_client_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label" id="intercomlabel" colspan="1">Intercom</td> <td class="info" colspan="1"> {{ computer.room.intercom_numbers if computer.room.intercom_numbers else 'Enter Data' }} </td> <td class="label" colspan="1">Checked-In</td> <td class="info checkin" colspan="2" id="{{computer.name}}_checked_in"> {{ computer.active_drive.last_checked_in if computer.active_drive.last_checked_in else 'Check Service' }} </td> <td class="label" colspan="2">Avid ISIS Client</td> <td class="info" colspan="2">{{computer.active_drive.isis_client_version}}</td> </tr> <tr class="tablesorter-childRow"> <td class="label">Notes</td> <td class="info" colspan="1">{{ computer.notes if computer.notes else ''}}</td> <td class="label">Swing Date</td> <td class="info" colspan="2">{{ computer.active_drive.last_changed_workgroup }}</td> <td class="label" colspan="2">Nvidia Driver</td> <td class="info " colspan="2">{{computer.active_drive.graphics_driver_version}}</td> </tr> {% endif %} {% endfor %} </tbody> </table> </div> <div id="bottom" class="bottom"> {% for workgroup in context['workgroup_list'] %} <a href="#" id="{{workgroup.shorthand}}" class="show_{{workgroup}}"> {{ workgroup.shorthand }} </a> {% endfor %} </div> </div> {% endblock %}8 , que enciende los tipos en la variante 998877666554443319 (a diferencia de simplemente agregar .begin()0 , que no tiene efecto en las referencias ):

  .begin()1  

¿Tiene sentido esto, y está bien? ¿Hay algo más que pueda estar haciendo, que es más legible / eficiente / etc.?

¡Gracias!

Original en ingles

Edit: added clarification for why I want this, and updated the code since I don't have any answers yet

I have a C++11 array-like class which (can be) a wrapper around a random-access iterator. Index-based access and .begin()/.end() can just pass through to the iterator, but there's a bit of complication when the object is const:

    template<class Size, typename DataIterator>     class Storage : public Size {         DataIterator iterator;     public:         Storage(const DataIterator &iterator, const Size &size) : Size(size), iterator(iterator) {}                  auto operator[](index_t i)                 -> decltype(iterator[i]) {             return iterator[i];         }         auto operator[](index_t i) const                 -> MakeConst<decltype(iterator[i])> {             return iterator[i];         }                  DataIterator begin() {return iterator;}         ConstWrapper<DataIterator> begin() const {return iterator;}         DataIterator end() {return iterator + this->size();}         ConstWrapper<DataIterator> end() const {return iterator + this->size();}     }; 

If we simply returned DataIterator from the const version of .begin() and .end(), then people holding a Storage const & would (incorrectly!) be able to modify the array through that iterator.

Containers like std::vector have two separate iterators (::iterator and ::const_iterator), but our Storage class only has the read-write one, so we synthesise one using ConstWrapper:

    template <typename Iterator>     class ConstWrapper {         Iterator iterator;          using traits = std::iterator_traits<Iterator>;     public:         using difference_type = typename traits::difference_type;         using value_type = typename traits::value_type;         using pointer = ConstWrapper;         using reference = MakeConst<typename traits::reference>;         using iterator_category = typename traits::iterator_category;              ConstWrapper() {}         ConstWrapper(const Iterator &iterator) : iterator(iterator) {}                  // The problematic cases:         auto operator[](index_t i) const                 -> MakeConst<decltype(iterator[i])> {             return iterator[i];         }         auto operator*() const                 -> MakeConst<decltype(*iterator)> {             return *iterator;         }          bool operator!= (const ConstWrapper& other) const {             return iterator != other.iterator;         }         /** All the other random-access iterator methods **/     };          // Specialisation to prevent infinite loops     template <typename Iterator>     class ConstWrapper<ConstWrapper<Iterator>> : ConstWrapper<Iterator> {     public:         using ConstWrapper<Iterator>::ConstWrapper;     }; 

The implementation forwards all the relevant methods, and has a specialisation for ConstWrapper<ConstWrapper<...>> so that it can't wrap itself.

A key part is MakeConst, which turns types into the correct const variant (unlike simply adding const, which has no effect on references):

    // Converts (T & -> T const &), and (T -> const T)     using MakeConst = typename std::conditional<         std::is_reference<T>::value,         typename std::remove_reference<T>::type const &,         const T     >::type; 

Does this make sense, and is it OK? Is there something else I could be doing which is more readable/efficient/etc.?

Thanks!

           
       
       

Lista de respuestas

2
 
vote

No creo que su especialización esté haciendo lo que crees que está haciendo. https://godbolt.org/z/gfh7sv

No quieres ConstWrapper<ConstWrapper<Iterator>> a heredado de 9988776655544331 ; Eso significaría que un 9988776655544332 "es-a-tipo-of" CW<I>3 , que no es cierto. No quieres una relación de herencia aquí. Lo que desea es simplemente para las especializaciones de Storage tO no envoltura DataIterator s que son especializaciones de ConstWrapper ya . La forma en que lo hace es con una capa extra de indirección de alias:

  template<class T> struct maybe_constwrap { using type = ConstWrapper<T>; }; template<class U> struct maybe_constwrap<ConstWrapper<U>> { using type = ConstWrapper<U>; };  template<class Size, typename DataIterator> class Storage : public Size { public:     using iterator = DataIterator;     using const_iterator = typename maybe_constwrap<DataIterator>::type;     ~~~ };   

ahora, si DataIterator es un 99887776655544339 , entonces tanto 998877766555443310 y ConstWrapper<Iterator>1 será literalmente el mismo Tipo ... que es lo que quieres.


Su ConstWrapper<Iterator>2 parece ser predicado en la idea dudosa de que ConstWrapper<Iterator>3 no va a ser asignable a. Eso es probable que cambie en C ++ 23. Consulte https://stackoverflow.com/questions/63412623/should-c20 -StDrangessOsT-Not-Need-to-Support-STDVectorBool para algún contexto.


Repetir un poco de metaprogramación en los tipos de retorno de ConstWrapper<Iterator>4 y ConstWrapper<Iterator>5 . Deben simplemente devolver el tipo ConstWrapper<Iterator>6 que ya ha computado anteriormente.

  ConstWrapper<Iterator>7  

Por cierto, estoy cambiando el nombre de su miembro de datos de ConstWrapper<Iterator>8 a ConstWrapper<Iterator>9 , porque sospecho que es una idea terrible, conceptos, en cuanto a tener un contenedor. Tipo de clase ISH con un miembro llamado CW<CW<I>>0 qué miembro es (a) no público, y (b) no es un tipo.


Su CW<CW<I>>1 Probablemente debería usar el Idiom de Amigo oculto:

  CW<CW<I>>2  

En C ++ 20, podría omitir teóricamente CW<CW<I>>3 y proporcionar CW<CW<I>>4

Pasando CW<CW<I>>5 por valor debe estar bien, porque solo tiene un iterador, y los iteradores son baratos a copiar.

 

I don't think your specialization is doing what you think it's doing. https://godbolt.org/z/Gfh7sv

You don't want ConstWrapper<ConstWrapper<Iterator>> to inherit from ConstWrapper<Iterator>; that would mean that a CW<CW<I>> "is-a-kind-of" CW<I>, which isn't true. You don't want an inheritance relationship here. What you want is simply for specializations of Storage to not wrap DataIterators that happen to be specializations of ConstWrapper already. The way you do that is with an extra layer of alias indirection:

template<class T> struct maybe_constwrap { using type = ConstWrapper<T>; }; template<class U> struct maybe_constwrap<ConstWrapper<U>> { using type = ConstWrapper<U>; };  template<class Size, typename DataIterator> class Storage : public Size { public:     using iterator = DataIterator;     using const_iterator = typename maybe_constwrap<DataIterator>::type;     ~~~ }; 

Now, if DataIterator is already a ConstWrapper, then both iterator and const_iterator will be literally the same type... which is what you want.


Your MakeConst seems to be predicated on the dubious idea that const _Bit_reference is not going to be assignable-to. That's likely to change in C++23. See https://stackoverflow.com/questions/63412623/should-c20-stdrangessort-not-need-to-support-stdvectorbool for some context.


You repeat some metaprogramming in the return types of operator* and operator[]. They should just return the type reference which you have already computed above.

reference operator*() const { return *it_; } 

Incidentally, I'm changing your data member's name from iterator to it_, because I suspect it is a terrible idea, Concepts-wise, to have a container-ish class type with a member named iterator which member is (A) not public, and (B) not a type.


Your operator!= should probably use the hidden friend idiom:

friend bool operator==(ConstWrapper a, ConstWrapper b) { return a.it_ == b.it_; } friend bool operator!=(ConstWrapper a, ConstWrapper b) { return a.it_ != b.it_; } 

In C++20 you could theoretically omit operator!= and provide operator== only. I don't know yet if that's a good idea.

Passing ConstWrapper by value should be fine, because it holds only an iterator, and iterators are cheap to copy.

 
 
   
   

Relacionados problema

20  Construyendo una buena biblioteca de plantillas C ++ 11 - Tiempo compilado enumeró la matriz enumulada [cerrada]  ( Building a good c11 template library compile time checked enum array ) 
cerrado. Esta pregunta es off-topic . Actualmente no está aceptando respuestas. ¿Quieres ...

13  ID de tipo único en C ++  ( Unique type id in c ) 
Necesito tener una identificación única para cualquier tipo en C ++ para un tipo de variante. ¿Este código es confiable para obtener la identificación? No me ...

11  Clon de variante de impulso  ( Clone of boost variant ) 
Como parte del aprendizaje C ++, con especial énfasis en C ++ 11, quería implementar el equivalente a la variante de Boost (ubicada AQUÍ ). Mi código está di...

3  ¿Podría este esquema de ejecución diferido ser más simple?  ( Could this deferred execution scheme be any simpler ) 
He creado este esquema para preservar las llamadas de la función hasta que estén disponibles todos los argumentos. La stub_op8 Las clases se reemplazarán co...

16  Implementación muy básica de la tupla  ( Very basic tuple implementation ) 
Me han metido la metaprogramación y las plantillas variadas en C ++, y me fui con esta implementación muy primitiva de una tupla: activityKey4 siendo la...

2  C ++ Socket Part-2 A (Utilidades)  ( C socket part 2 a utilities ) 
Este es el código que utilizo para construir dinámicamente los mensajes de error. Utilidad.H #ifndef THORSANVIL_SOCKET_UTILITY_H #define THORSANVIL_SOCKE...

6  Biblioteca de listas de metaprogramas de pequeña plantilla  ( Small template metaprogramming list library ) 
Entonces, tiempo para explorar las profundidades de asustadizo de la metaprogramación de plantillas (bueno, aterrador para mí, de todos modos). Esta bibliot...

5  C ++ Elija entre funciones de implementación de tiempo de ejecución y tiempo de compilación  ( C choose between runtime and compile time implementation functions ) 
Escribí una pequeña función de envoltura para elegir entre Tiempo de ejecución (STD) 99887766555443318 y una versión de ConsexPR, como continuación de la cl...

6  Clase de matriz multidimensional simple en C ++ 11  ( Simple multi dimensional array class in c11 ) 
La nueva versión del código se puede revisar en Clase de matriz multidimensional simple en C ++ 11 - Seguimiento . El siguiente código implementa una clas...

11  Selección Clasificación de una lista de tipos (Tiempo de compilación)  ( Selection sorting a type list compile time ) 
Esta pregunta tiene la plantilla 998877666554433665544336 que ordena la plantilla variada de una tupla usando un comparador (cualquier plantilla que toma do...




© 2022 respuesta.top Reservados todos los derechos. Centro de preguntas y respuestas reservados todos los derechos