|
|
От: |
niXman
|
https://github.com/niXman |
| Дата: | 10.04.14 12:11 | ||
| Оценка: | |||
#include <iostream>
#include <map>
struct noncopyable {
noncopyable() {std::cout << "noncopyable ctor" << std::endl;}
noncopyable(const noncopyable &) = delete;
noncopyable& operator=(const noncopyable &) = delete;
};
int main() {
std::map<int, noncopyable> cp;
cp.insert(std::make_pair(3, noncopyable()));
}(а как тут сделать спойлер?)g++ -std=c++11 mapmove.cpp -omapmove && ./mapmove
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 mapmove.cpp:2:
/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 = int; _T2 = noncopyable]’:
/usr/include/c++/4.8/bits/stl_pair.h:281:72: required from ‘constexpr std::pair<typename std::__decay_and_strip<_Tp>::__type, typename std::__decay_and_strip<_T2>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = noncopyable; typename std::__decay_and_strip<_T2>::__type = noncopyable; typename std::__decay_and_strip<_Tp>::__type = int]’
mapmove.cpp:18:43: required from here
/usr/include/c++/4.8/bits/stl_pair.h:134:45: error: use of deleted function ‘noncopyable::noncopyable(const noncopyable&)’
: first(std::forward<_U1>(__x)), second(__y) { }
^
mapmove.cpp:12:2: error: declared here
noncopyable(const noncopyable &) = delete;
^
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 mapmove.cpp:2:
/usr/include/c++/4.8/bits/stl_pair.h: In instantiation of ‘constexpr std::pair<typename std::__decay_and_strip<_Tp>::__type, typename std::__decay_and_strip<_T2>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = noncopyable; typename std::__decay_and_strip<_T2>::__type = noncopyable; typename std::__decay_and_strip<_Tp>::__type = int]’:
mapmove.cpp:18:43: required from here
/usr/include/c++/4.8/bits/stl_pair.h:281:72: error: use of deleted function ‘constexpr std::pair<_T1, _T2>::pair(std::pair<_T1, _T2>&&) [with _T1 = int; _T2 = noncopyable]’
return __pair_type(std::forward<_T1>(__x), std::forward<_T2>(__y));
^
/usr/include/c++/4.8/bits/stl_pair.h:128:17: note: ‘constexpr std::pair<_T1, _T2>::pair(std::pair<_T1, _T2>&&) [with _T1 = int; _T2 = noncopyable]’ is implicitly deleted because the default definition would be ill-formed:
constexpr pair(pair&&) = default;
^
/usr/include/c++/4.8/bits/stl_pair.h:128:17: error: use of deleted function ‘noncopyable::noncopyable(const noncopyable&)’
mapmove.cpp:12:2: error: declared here
noncopyable(const noncopyable &) = delete;
^
mapmove.cpp: In function ‘int main()’:
mapmove.cpp:18:44: error: no matching function for call to ‘std::map<int, noncopyable>::insert(std::pair<int, noncopyable>)’
cp.insert(std::make_pair(3, noncopyable()));
^
mapmove.cpp:18:44: note: candidates are:
In file included from /usr/include/c++/4.8/map:61:0,
from mapmove.cpp:3:
/usr/include/c++/4.8/bits/stl_map.h:594:7: note: std::pair<typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(const value_type&) [with _Key = int; _Tp = noncopyable; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, noncopyable> >; typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::iterator = std::_Rb_tree_iterator<std::pair<const int, noncopyable> >; std::map<_Key, _Tp, _Compare, _Alloc>::value_type = std::pair<const int, noncopyable>]
insert(const value_type& __x)
^
/usr/include/c++/4.8/bits/stl_map.h:594:7: note: no known conversion for argument 1 from ‘std::pair<int, noncopyable>’ to ‘const value_type& {aka const std::pair<const int, noncopyable>&}’
/usr/include/c++/4.8/bits/stl_map.h:602:9: note: template<class _Pair, class> std::pair<typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::other>::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(_Pair&&) [with _Pair = _Pair; <template-parameter-2-2> = <template-parameter-1-2>; _Key = int; _Tp = noncopyable; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, noncopyable> >]
insert(_Pair&& __x)
^
/usr/include/c++/4.8/bits/stl_map.h:602:9: note: template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/stl_map.h:598:32: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
template<typename _Pair, typename = typename
^
/usr/include/c++/4.8/bits/stl_map.h:615:7: note: void std::map<_Key, _Tp, _Compare, _Alloc>::insert(std::initializer_list<std::pair<const _Key, _Tp> >) [with _Key = int; _Tp = noncopyable; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, noncopyable> >]
insert(std::initializer_list<value_type> __list)
^
/usr/include/c++/4.8/bits/stl_map.h:615:7: note: no known conversion for argument 1 from ‘std::pair<int, noncopyable>’ to ‘std::initializer_list<std::pair<const int, noncopyable> >’
/usr/include/c++/4.8/bits/stl_map.h:644:7: note: std::map<_Key, _Tp, _Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::insert(std::map<_Key, _Tp, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = int; _Tp = noncopyable; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, noncopyable> >; std::map<_Key, _Tp, _Compare, _Alloc>::iterator = std::_Rb_tree_iterator<std::pair<const int, noncopyable> >; std::map<_Key, _Tp, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<const int, noncopyable> >; std::map<_Key, _Tp, _Compare, _Alloc>::value_type = std::pair<const int, noncopyable>]
insert(const_iterator __position, const value_type& __x)
^
/usr/include/c++/4.8/bits/stl_map.h:644:7: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/4.8/bits/stl_map.h:655:9: note: template<class _Pair, class> std::map<_Key, _Tp, _Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::insert(std::map<_Key, _Tp, _Compare, _Alloc>::const_iterator, _Pair&&) [with _Pair = _Pair; <template-parameter-2-2> = <template-parameter-1-2>; _Key = int; _Tp = noncopyable; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, noncopyable> >]
insert(const_iterator __position, _Pair&& __x)
^
/usr/include/c++/4.8/bits/stl_map.h:655:9: note: template argument deduction/substitution failed:
mapmove.cpp:18:44: note: cannot convert ‘std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = noncopyable; typename std::__decay_and_strip<_T2>::__type = noncopyable; typename std::__decay_and_strip<_Tp>::__type = int]((* & noncopyable()))’ (type ‘std::pair<int, noncopyable>’) to type ‘std::map<int, noncopyable>::const_iterator {aka std::_Rb_tree_const_iterator<std::pair<const int, noncopyable> >}’
cp.insert(std::make_pair(3, noncopyable()));
^
In file included from /usr/include/c++/4.8/map:61:0,
from mapmove.cpp:3:
/usr/include/c++/4.8/bits/stl_map.h:670:9: note: template<class _InputIterator> void std::map<_Key, _Tp, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = int; _Tp = noncopyable; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, noncopyable> >]
insert(_InputIterator __first, _InputIterator __last)
^
/usr/include/c++/4.8/bits/stl_map.h:670:9: note: template argument deduction/substitution failed:
mapmove.cpp:18:44: note: candidate expects 2 arguments, 1 provided
cp.insert(std::make_pair(3, noncopyable()));
^
cp.insert(std::make_pair(3, std::move(noncopyable()))); cp.insert(std::move(std::make_pair(3, noncopyable())));