std::vector
には
cpp
1template <class InputIter> 2vector(InputIter first, InputIter last, 3 const Allocator& a = Allocator());
のようなコンストラクタがC++03より存在します。
vector::コンストラクタ - cpprefjp C++日本語リファレンス
によると、
C++03までは整数のペアを渡せたようですが、
C++11 では
InputIter
が入力イテレータの要件を満たさなければオーバーロード解決に参加しないように変更された。
と書かれています。しかし規格書(N4140)を参照すると、
template <class InputIterator> vector(InputIterator first, InputIterator last, const Allocator& = Allocator()); 9 Effects: Constructs a vector equal to the range [first,last), using the specified allocator. 10 Complexity: Makes only N calls to the copy constructor of T (where N is the distance between first and last) and no reallocations if iterators first and last are of forward, bidirectional, or random access categories. It makes order N calls to the copy constructor of T and order log(N) reallocations if they are just input iterators.
のようにあり、それらしい文言はありません。
実際libstdc++の実装を見ると、
cpp
1 template<typename _InputIterator, 2 typename = std::_RequireInputIter<_InputIterator>> 3 vector(_InputIterator __first, _InputIterator __last, 4 const allocator_type& __a = allocator_type()) 5 : _Base(__a) 6 { _M_initialize_dispatch(__first, __last, __false_type()); } 7
のようにSFINAEで弾くように書かれています。
ところでVisial Studio 2017の実装を見ると、
cpp
1 template<class _Iter, 2 class = enable_if_t<_Is_iterator_v<_Iter>>> 3 vector(_Iter _First, _Iter _Last, const _Alloc& _Al = _Alloc()) 4 : _Mybase(_Al) 5 { // construct from [_First, _Last) with optional allocator 6 _DEBUG_RANGE(_First, _Last); 7 _Range_construct_or_tidy(_Unchecked(_First), _Unchecked(_Last), _Iter_cat_t<_Iter>{}); 8 }
のようになっており、これは入力イテレータであるかの検査と言うよりはイテレータであるかの検査に見えます。
質問です。
- 入力イテレータではないときオーバーロード解決から外すというこの文言の根拠となる規格書の文面はどこか
- MSVCの実装は規格に準拠しているか
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/31 15:16
2018/01/31 15:51
2018/02/01 02:00
2018/02/02 03:14
2018/11/28 18:58