<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif,"EmojiFont","Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<p style="margin-top:0; margin-bottom:0"></p>
<span id="ms-rterangepaste-start"></span>
<div>
<div>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif,serif,"EmojiFont"">
<p style="margin-top:0; margin-bottom:0">Hi, all.<br>
</p>
<p style="margin-top:0; margin-bottom:0">I noticed several issues with missing header dependencies. Specifically the following code compiles with libstdc++ but not libc++:</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<div>$ cat istream-1.cc <br>
#include <iterator><br>
typedef std::istreambuf_iterator<char> iter;<br>
<br>
bool foo(const iter& a, const iter& b)<br>
{<br>
return a == b;<br>
}</div>
<div><br>
</div>
<div>$ clang++ -stdlib=libc++ istream-1.cc<br>
In file included from istream-1.cc:1:<br>
/opt/data/llvm/install/bin/../include/c++/v1/iterator:948:32: error: implicit instantiation of undefined template 'std::__1::char_traits<char>'<br>
typename _Traits::off_type, _CharT*,<br>
^<br>
istream-1.cc:6:14: note: in instantiation of template class 'std::__1::istreambuf_iterator<char, std::__1::char_traits<char> >' requested here<br>
return a == b;<br>
^<br>
/opt/data/llvm/install/bin/../include/c++/v1/iosfwd:100:53: note: template is declared here<br>
template<class _CharT> struct _LIBCPP_TEMPLATE_VIS char_traits;<br>
<br>
</div>
(snip)
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">I.e., the definition of char_traits is missing. It can be fixed by including the <__string> header, but then it would fail due to missing std::basic_<span>streambuf</span>. Including <<span>streambuf</span>> will make
the code compile.<br>
</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">Two more issues:</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<div>$ cat iostream-iter.cc<br>
<div>#include <iterator><br>
typedef std::istream_iterator<char, char> istream_iter;<br>
typedef std::ostream_iterator<char, char> ostream_iter;<br>
<br>
void foo(istream_iter::istream_type& stream)<br>
{<br>
istream_iter iter(stream);<br>
}<br>
<br>
void bar(ostream_iter::ostream_type) { }<br>
</div>
<br>
</div>
<div>
<div>$ clang++ -stdlib=libc++ iostream-iter.cc<br>
iostream-iter.cc:10:36: error: implicit instantiation of undefined template 'std::__1::basic_ostream<char, std::__1::char_traits<char> >'<br>
void bar(ostream_iter::ostream_type) { }<br>
^<br>
/opt/data/llvm/install/bin/../include/c++/v1/iosfwd:111:32: note: template is declared here<br>
class _LIBCPP_TEMPLATE_VIS basic_ostream;<br>
^<br>
In file included from iostream-iter.cc:1:<br>
/opt/data/llvm/install/bin/../include/c++/v1/iterator:892:33: error: invalid operands to binary expression ('std::__1::istream_iterator<char, char, std::__1::char_traits<char>, long>::istream_type'<br>
(aka 'basic_istream<char, std::__1::char_traits<char> >') and 'int')<br>
if (!(*__in_stream_ >> __value_))<br>
~~~~~~~~~~~~~ ^ ~~~~~~~~<br>
iostream-iter.cc:7:18: note: in instantiation of member function 'std::__1::istream_iterator<char, char, std::__1::char_traits<char>, long>::istream_iterator' requested here<br>
istream_iter iter(stream);<br>
^<br>
2 errors generated.</div>
</div>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">Here foo requires the definitions of basic_istream::operator>> (for fundamental types) to be available, and bar requires basic_ostream copy c-tor (note that the
<span>stream</span> is passed by value). These errors can be fixed by including <<span>istream</span>> and <<span>ostream</span>> respectively.</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">My question is: should these headers be included into <iterator> or am I missing some wording in the C++ standard, that requires the user to include them?<br>
</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<div id="x_Signature">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif,"EmojiFont","Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<p style="margin-top:0; margin-bottom:0">-- <br>
</p>
<div class="x_m_-1104065515082820511gmail_signature">Regards,<br>
Mikhail Maltsev</div>
</div>
</div>
</div>
</div>
</div>
<span class="PersonaPaneLauncher">
<div class="_pe_d _pe_62" tabindex="-1"></div>
</span>
<div class="_rp_k" tabindex="-1" style="">
<div class="_qc_F ms-bg-color-white _qc_G">
<hr class="_qc_B">
<div tabindex="-1" class="_qc_y ms-border-color-neutralLight _qc_z"></div>
</div>
</div>
</div>
<span id="ms-rterangepaste-end"></span>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif,"EmojiFont","Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<div class="m_-1104065515082820511gmail_signature"></div>
<p></p>
</div>
</div>
</div>
</body>
</html>