简体   繁体   中英

Is std::istream_iterator<int> trivially copy constuctible?

Why does this program compile on MSVC but not on GCC and Clang? godbolt

#include <iterator>
#include <type_traits>

static_assert(std::is_trivially_copy_constructible_v<std::istream_iterator<int>>);

According to [istream.iterator.cons]/6 , the constructor must be trivial. Does it relate to P0738 which moves the wording from Effects to Remarks ?

Seems like there is a difference in implementation. The gcc library has a copy constructor

  istream_iterator(const istream_iterator& __obj)
  : _M_stream(__obj._M_stream), _M_value(__obj._M_value),
    _M_ok(__obj._M_ok)
  { }

which is non-trivial.

MSVC does not, and apparently relies on a compiler generated one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM