Changeset a554e5f4 for src/Common
- Timestamp:
- Feb 9, 2022, 3:33:42 PM (4 years ago)
- 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. - Location:
- src/Common
- Files:
-
- 2 edited
-
CodeLocation.h (modified) (2 diffs)
-
utility.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/CodeLocation.h
r21a99cc ra554e5f4 26 26 CodeLocation() = default; 27 27 28 28 29 /// Create a new CodeLocation with the given values. 29 30 CodeLocation( const char* filename, int lineno ) … … 33 34 34 35 CodeLocation( const CodeLocation& rhs ) = default; 36 CodeLocation( CodeLocation&& rhs ) = default; 37 CodeLocation& operator=( const CodeLocation & ) = default; 38 CodeLocation& operator=( CodeLocation && ) = default; 35 39 36 40 bool isSet () const { -
src/Common/utility.h
r21a99cc ra554e5f4 371 371 } 372 372 373 template< typename T > 374 struct 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 421 template< typename T > 422 enumerate_t<T> enumerate( T & ref ) { 423 return enumerate_t< T >{ ref }; 424 } 425 426 template< typename T > 427 const enumerate_t< const T > enumerate( const T & ref ) { 428 return enumerate_t< const T >{ ref }; 429 } 430 373 431 template< typename OutType, typename Range, typename Functor > 374 432 OutType map_range( const Range& range, Functor&& functor ) {
Note:
See TracChangeset
for help on using the changeset viewer.