fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3. #include <map>
  4.  
  5. struct A {
  6. A() {
  7. std::cout << "A was created" << std::endl;
  8. }
  9.  
  10. A(A &&) = delete;
  11. A(A const &) = delete;
  12. A& operator=(const A& other) = delete;
  13.  
  14. ~A() {
  15. std::cout << "A was destroyed" << std::endl;
  16. }
  17. };
  18.  
  19. int main() {
  20. std::map<int, A> theMap {{1, A()}, {2, A()}};
  21.  
  22. std::cout << "Starting for loop now" << std::endl;
  23.  
  24. for (auto const & pair : theMap) {
  25. std::cout << "performed an iteration" << std::endl;
  26. }
  27.  
  28. std::cout << "for loop finished" << std::endl;
  29. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/4.8/bits/char_traits.h:39,
                 from /usr/include/c++/4.8/ios:40,
                 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/stl_pair.h: In instantiation of ‘constexpr std::pair<_T1, _T2>::pair(_U1&&, const _T2&) [with _U1 = int; <template-parameter-2-2> = void; _T1 = const int; _T2 = A]’:
prog.cpp:20:48:   required from here
/usr/include/c++/4.8/bits/stl_pair.h:134:45: error: use of deleted function ‘A::A(const A&)’
  : first(std::forward<_U1>(__x)), second(__y) { }
                                             ^
prog.cpp:11:5: error: declared here
     A(A const &) = delete;
     ^
prog.cpp: In function ‘int main()’:
prog.cpp:24:23: warning: unused variable ‘pair’ [-Wunused-variable]
     for (auto const & pair : theMap) {
                       ^
In file included from /usr/include/c++/4.8/map:60:0,
                 from prog.cpp:3:
/usr/include/c++/4.8/bits/stl_tree.h: In instantiation of ‘std::_Rb_tree_node<_Val>::_Rb_tree_node(_Args&& ...) [with _Args = {const std::pair<const int, A>&}; _Val = std::pair<const int, A>]’:
/usr/include/c++/4.8/ext/new_allocator.h:120:4:   required from ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::_Rb_tree_node<std::pair<const int, A> >; _Args = {const std::pair<const int, A>&}; _Tp = std::_Rb_tree_node<std::pair<const int, A> >]’
/usr/include/c++/4.8/bits/alloc_traits.h:254:4:   required from ‘static typename std::enable_if<std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::value, void>::type std::allocator_traits<_Alloc>::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = std::_Rb_tree_node<std::pair<const int, A> >; _Args = {const std::pair<const int, A>&}; _Alloc = std::allocator<std::_Rb_tree_node<std::pair<const int, A> > >; typename std::enable_if<std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::value, void>::type = void]’
/usr/include/c++/4.8/bits/alloc_traits.h:393:57:   required from ‘static decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) std::allocator_traits<_Alloc>::construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = std::_Rb_tree_node<std::pair<const int, A> >; _Args = {const std::pair<const int, A>&}; _Alloc = std::allocator<std::_Rb_tree_node<std::pair<const int, A> > >; decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) = <type error>]’
/usr/include/c++/4.8/bits/stl_tree.h:408:36:   required from ‘std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_create_node(_Args&& ...) [with _Args = {const std::pair<const int, A>&}; _Key = int; _Val = std::pair<const int, A>; _KeyOfValue = std::_Select1st<std::pair<const int, A> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, A> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type = std::_Rb_tree_node<std::pair<const int, A> >*]’
/usr/include/c++/4.8/bits/stl_tree.h:1023:66:   required from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Base_ptr, std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Base_ptr, _Arg&&) [with _Arg = const std::pair<const int, A>&; _Key = int; _Val = std::pair<const int, A>; _KeyOfValue = std::_Select1st<std::pair<const int, A> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, A> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator = std::_Rb_tree_iterator<std::pair<const int, A> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Base_ptr = std::_Rb_tree_node_base*]’
/usr/include/c++/4.8/bits/stl_tree.h:1482:33:   required from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique_(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator, _Arg&&) [with _Arg = const std::pair<const int, A>&; _Key = int; _Val = std::pair<const int, A>; _KeyOfValue = std::_Select1st<std::pair<const int, A> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, A> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator = std::_Rb_tree_iterator<std::pair<const int, A> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<const int, A> >]’
/usr/include/c++/4.8/bits/stl_tree.h:1722:37:   required from ‘void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_II, _II) [with _InputIterator = const std::pair<const int, A>*; _Key = int; _Val = std::pair<const int, A>; _KeyOfValue = std::_Select1st<std::pair<const int, A> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, A> >]’
/usr/include/c++/4.8/bits/stl_map.h:210:9:   required from ‘std::map<_Key, _Tp, _Compare, _Alloc>::map(std::initializer_list<std::pair<const _Key, _Tp> >, const _Compare&, const allocator_type&) [with _Key = int; _Tp = A; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, A> >; std::map<_Key, _Tp, _Compare, _Alloc>::allocator_type = std::allocator<std::pair<const int, A> >]’
prog.cpp:20:48:   required from here
/usr/include/c++/4.8/bits/stl_tree.h:140:49: error: use of deleted function ‘constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const int; _T2 = A]’
    _M_value_field(std::forward<_Args>(__args)...) { }
                                                 ^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/4.8/bits/char_traits.h:39,
                 from /usr/include/c++/4.8/ios:40,
                 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/stl_pair.h:127:17: note: ‘constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const int; _T2 = A]’ is implicitly deleted because the default definition would be ill-formed:
       constexpr pair(const pair&) = default;
                 ^
/usr/include/c++/4.8/bits/stl_pair.h:127:17: error: use of deleted function ‘A::A(const A&)’
prog.cpp:11:5: error: declared here
     A(A const &) = delete;
     ^
stdout
Standard output is empty