Changeset a554e5f4 for src/Common


Ignore:
Timestamp:
Feb 9, 2022, 3:33:42 PM (4 years ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
850aff1
Parents:
21a99cc (diff), c4f81702 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/Common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Common/CodeLocation.h

    r21a99cc ra554e5f4  
    2626        CodeLocation() = default;
    2727
     28
    2829        /// Create a new CodeLocation with the given values.
    2930        CodeLocation( const char* filename, int lineno )
     
    3334
    3435        CodeLocation( const CodeLocation& rhs ) = default;
     36        CodeLocation( CodeLocation&& rhs ) = default;
     37        CodeLocation& operator=( const CodeLocation & ) = default;
     38        CodeLocation& operator=( CodeLocation && ) = default;
    3539
    3640        bool isSet () const {
  • src/Common/utility.h

    r21a99cc ra554e5f4  
    371371}
    372372
     373template< typename T >
     374struct enumerate_t {
     375        template<typename val_t>
     376        struct value_t {
     377                val_t & val;
     378                size_t idx;
     379        };
     380
     381        template< typename iter_t, typename val_t >
     382        struct iterator_t {
     383                iter_t it;
     384                size_t idx;
     385
     386                iterator_t( iter_t _it, size_t _idx ) : it(_it), idx(_idx) {}
     387
     388                value_t<val_t> operator*() const { return value_t<val_t>{ *it, idx }; }
     389
     390                bool operator==(const iterator_t & o) const { return o.it == it; }
     391                bool operator!=(const iterator_t & o) const { return o.it != it; }
     392
     393                iterator_t & operator++() {
     394                        it++;
     395                        idx++;
     396                        return *this;
     397                }
     398
     399                using difference_type   = typename std::iterator_traits< iter_t >::difference_type;
     400                using value_type        = value_t<val_t>;
     401                using pointer           = value_t<val_t> *;
     402                using reference         = value_t<val_t> &;
     403                using iterator_category = std::forward_iterator_tag;
     404        };
     405
     406        T & ref;
     407
     408        using iterator = iterator_t< typename T::iterator, typename T::value_type >;
     409        using const_iterator = iterator_t< typename T::const_iterator, const typename T::value_type >;
     410
     411        iterator begin() { return iterator( ref.begin(), 0 ); }
     412        iterator end()   { return iterator( ref.end(), ref.size() ); }
     413
     414        const_iterator begin() const { return const_iterator( ref.cbegin(), 0 ); }
     415        const_iterator end()   const { return const_iterator( ref.cend(), ref.size() ); }
     416
     417        const_iterator cbegin() const { return const_iterator( ref.cbegin(), 0 ); }
     418        const_iterator cend()   const { return const_iterator( ref.cend(), ref.size() ); }
     419};
     420
     421template< typename T >
     422enumerate_t<T> enumerate( T & ref ) {
     423        return enumerate_t< T >{ ref };
     424}
     425
     426template< typename T >
     427const enumerate_t< const T > enumerate( const T & ref ) {
     428        return enumerate_t< const T >{ ref };
     429}
     430
    373431template< typename OutType, typename Range, typename Functor >
    374432OutType map_range( const Range& range, Functor&& functor ) {
Note: See TracChangeset for help on using the changeset viewer.