fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template <typename Container>
  5. class reverse_adaptor
  6. {
  7. public: // Construction
  8. reverse_adaptor(Container &container) :
  9. m_container(container)
  10. {}
  11.  
  12. public: // STL container static polymorphism
  13. auto begin() const -> decltype(this->m_container.rbegin())
  14. {
  15. return m_container.rbegin();
  16. }
  17.  
  18. auto end() const -> decltype(this->m_container.rend())
  19. {
  20. return m_container.rend();
  21. }
  22.  
  23. private: // Members
  24. Container &m_container;
  25. };
  26.  
  27. template <typename Container>
  28. reverse_adaptor<Container> make_reverse_adaptor(Container &container)
  29. {
  30. return reverse_adaptor<Container>(container);
  31. }
  32.  
  33. int main()
  34. {
  35. std::vector<int> test = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  36. for (const int i : make_reverse_adaptor(test))
  37. {
  38. std::cout << "i = " << i << std::endl;
  39. }
  40. return 0;
  41. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘class reverse_adaptor<std::vector<int> >’:
prog.cpp:36:46:   required from here
prog.cpp:13:10: error: ‘const class reverse_adaptor<std::vector<int> >’ has no member named ‘m_container’
     auto begin() const -> decltype(this->m_container.rbegin())
          ^
prog.cpp:18:10: error: ‘const class reverse_adaptor<std::vector<int> >’ has no member named ‘m_container’
     auto end() const -> decltype(this->m_container.rend())
          ^
prog.cpp: In function ‘int main()’:
prog.cpp:36:46: error: no matching function for call to ‘begin(reverse_adaptor<std::vector<int> >&)’
  for (const int i : make_reverse_adaptor(test))
                                              ^
prog.cpp:36:46: note: candidates are:
In file included from /usr/include/c++/4.8/bits/basic_string.h:42:0,
                 from /usr/include/c++/4.8/string:52,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/initializer_list:89:5: note: template<class _Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)
     begin(initializer_list<_Tp> __ils) noexcept
     ^
/usr/include/c++/4.8/initializer_list:89:5: note:   template argument deduction/substitution failed:
prog.cpp:36:46: note:   ‘reverse_adaptor<std::vector<int> >’ is not derived from ‘std::initializer_list<_Tp>’
  for (const int i : make_reverse_adaptor(test))
                                              ^
In file included from /usr/include/c++/4.8/string:51:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/range_access.h:87:5: note: template<class _Tp, unsigned int _Nm> _Tp* std::begin(_Tp (&)[_Nm])
     begin(_Tp (&__arr)[_Nm])
     ^
/usr/include/c++/4.8/bits/range_access.h:87:5: note:   template argument deduction/substitution failed:
prog.cpp:36:46: note:   mismatched types ‘_Tp [_Nm]’ and ‘reverse_adaptor<std::vector<int> >’
  for (const int i : make_reverse_adaptor(test))
                                              ^
In file included from /usr/include/c++/4.8/string:51:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/range_access.h:58:5: note: template<class _Container> decltype (__cont.begin()) std::begin(const _Container&)
     begin(const _Container& __cont) -> decltype(__cont.begin())
     ^
/usr/include/c++/4.8/bits/range_access.h:58:5: note:   template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/range_access.h: In substitution of ‘template<class _Container> decltype (__cont.begin()) std::begin(const _Container&) [with _Container = reverse_adaptor<std::vector<int> >]’:
prog.cpp:36:46:   required from here
/usr/include/c++/4.8/bits/range_access.h:58:5: error: ‘const class reverse_adaptor<std::vector<int> >’ has no member named ‘begin’
/usr/include/c++/4.8/bits/range_access.h:48:5: note: template<class _Container> decltype (__cont.begin()) std::begin(_Container&)
     begin(_Container& __cont) -> decltype(__cont.begin())
     ^
/usr/include/c++/4.8/bits/range_access.h:48:5: note:   template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/range_access.h: In substitution of ‘template<class _Container> decltype (__cont.begin()) std::begin(_Container&) [with _Container = reverse_adaptor<std::vector<int> >]’:
prog.cpp:36:46:   required from here
/usr/include/c++/4.8/bits/range_access.h:48:5: error: ‘class reverse_adaptor<std::vector<int> >’ has no member named ‘begin’
prog.cpp:36:46: error: no matching function for call to ‘end(reverse_adaptor<std::vector<int> >&)’
  for (const int i : make_reverse_adaptor(test))
                                              ^
prog.cpp:36:46: note: candidates are:
In file included from /usr/include/c++/4.8/bits/basic_string.h:42:0,
                 from /usr/include/c++/4.8/string:52,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/initializer_list:99:5: note: template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
     end(initializer_list<_Tp> __ils) noexcept
     ^
/usr/include/c++/4.8/initializer_list:99:5: note:   template argument deduction/substitution failed:
prog.cpp:36:46: note:   ‘reverse_adaptor<std::vector<int> >’ is not derived from ‘std::initializer_list<_Tp>’
  for (const int i : make_reverse_adaptor(test))
                                              ^
In file included from /usr/include/c++/4.8/string:51:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/range_access.h:97:5: note: template<class _Tp, unsigned int _Nm> _Tp* std::end(_Tp (&)[_Nm])
     end(_Tp (&__arr)[_Nm])
     ^
/usr/include/c++/4.8/bits/range_access.h:97:5: note:   template argument deduction/substitution failed:
prog.cpp:36:46: note:   mismatched types ‘_Tp [_Nm]’ and ‘reverse_adaptor<std::vector<int> >’
  for (const int i : make_reverse_adaptor(test))
                                              ^
In file included from /usr/include/c++/4.8/string:51:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/range_access.h:78:5: note: template<class _Container> decltype (__cont.end()) std::end(const _Container&)
     end(const _Container& __cont) -> decltype(__cont.end())
     ^
/usr/include/c++/4.8/bits/range_access.h:78:5: note:   template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/range_access.h: In substitution of ‘template<class _Container> decltype (__cont.end()) std::end(const _Container&) [with _Container = reverse_adaptor<std::vector<int> >]’:
prog.cpp:36:46:   required from here
/usr/include/c++/4.8/bits/range_access.h:78:5: error: ‘const class reverse_adaptor<std::vector<int> >’ has no member named ‘end’
/usr/include/c++/4.8/bits/range_access.h:68:5: note: template<class _Container> decltype (__cont.end()) std::end(_Container&)
     end(_Container& __cont) -> decltype(__cont.end())
     ^
/usr/include/c++/4.8/bits/range_access.h:68:5: note:   template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/range_access.h: In substitution of ‘template<class _Container> decltype (__cont.end()) std::end(_Container&) [with _Container = reverse_adaptor<std::vector<int> >]’:
prog.cpp:36:46:   required from here
/usr/include/c++/4.8/bits/range_access.h:68:5: error: ‘class reverse_adaptor<std::vector<int> >’ has no member named ‘end’
stdout
Standard output is empty