Advertisement
szaszm01

gcc bug source gccbug.cpp

Aug 27th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <type_traits>
  2. #include <iostream>
  3.  
  4. template<typename T, typename Param>
  5. concept bool UnaryFunction = requires(const T& func) {
  6.     func(std::declval<Param>());
  7. };
  8.  
  9. template<typename IT, typename Func>
  10. requires UnaryFunction<Func, decltype(*std::declval<IT>())>
  11. Func for_each(IT first, IT last, Func func)
  12. {
  13.     for(auto it = first; it != last; ++it) {
  14.         func(*it);
  15.     }
  16.     return func;
  17. }
  18.  
  19. int main() {
  20.     auto numbers = { 1, 2, 3, 4, 5 };
  21.     std::cout << "numbers:\n";
  22.  
  23.     // gcc 7.2 segfaulted for some reason at the next statement
  24.     for_each(numbers.begin(), numbers.end(), [](auto n) {
  25.         std::cout << n << '\n';
  26.     });
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement