Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <array>
  2. #include "A.h"
  3. #include "printer.hpp"
  4.  
  5. template <typename Collection>
  6. auto incrementIfPossible(Collection&& collection) {
  7.     for (auto&& item : collection) {
  8.         using Item = decltype(item);    
  9.         constexpr bool isMutable = !std::is_const_v<std::remove_reference_t<Item>>;
  10.        
  11.         if constexpr (isMutable) {
  12.             ++item;
  13.         }
  14.     }
  15. }
  16.  
  17. auto main() -> int {  
  18.     printLn("=== main begin ==========================");                      
  19.    
  20.     using Arr = std::array<A, 3>;
  21.    
  22.     incrementIfPossible(Arr {{ {3}, {5}, {7} }});
  23.    
  24.     const Arr carr {{ {9}, {11}, {13} }};
  25.     incrementIfPossible(carr);
  26.    
  27.     printLn("=== main end ============================");      
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement