Changeset 45a091b


Ignore:
Timestamp:
Nov 15, 2023, 11:55:59 AM (8 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
b8b5535
Parents:
1ccae59
Message:

It turns out enumerate does work if you use this very particular form of the for loop added in C++17. Ironically in this simple vector case it is about as complex. Swapped the order of fields in the enuemate value to make the binding read key-then-value.

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Common/Iterate.hpp

    r1ccae59 r45a091b  
    5858        template<typename val_t>
    5959        struct value_t {
     60                size_t idx;
    6061                val_t & val;
    61                 size_t idx;
    6262        };
    6363
     
    6969                iterator_t( iter_t _it, size_t _idx ) : it(_it), idx(_idx) {}
    7070
    71                 value_t<val_t> operator*() const { return value_t<val_t>{ *it, idx }; }
     71                value_t<val_t> operator*() const { return value_t<val_t>{ idx, *it }; }
    7272
    7373                bool operator==(const iterator_t & o) const { return o.it == it; }
  • src/Concurrency/WaitforNew.cpp

    r1ccae59 r45a091b  
    450450        );
    451451
    452         // For some reason, enumerate doesn't work here because of references.
    453         for ( size_t i = 0 ; i < waitfor->clauses.size() ; ++i ) {
     452        for ( const auto & [i, clause] : enumerate( waitfor->clauses ) ) {
    454453                theSwitch->cases.push_back(
    455454                        new ast::CaseClause( location,
     
    457456                                {
    458457                                        new ast::CompoundStmt( location, {
    459                                                 waitfor->clauses[i]->stmt,
     458                                                clause->stmt,
    460459                                                new ast::BranchStmt( location,
    461460                                                        ast::BranchStmt::Break,
     
    538537        ast::Stmt       * setter      = makeSetter( location, flag );
    539538
    540         // For some reason, enumerate doesn't work here because of references.
    541         for ( size_t i = 0 ; i < stmt->clauses.size() ; ++i ) {
    542                 init_clause( comp, acceptables, i, stmt->clauses[i], setter );
     539        for ( const auto & [i, clause] : enumerate( stmt->clauses ) ) {
     540                init_clause( comp, acceptables, i, clause, setter );
    543541        }
    544542
Note: See TracChangeset for help on using the changeset viewer.