std::ostrea...eam_iterator(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– std::ostrea...eam_iterator(3) πŸ’–

okay so this is from the C++ Standard Libary manual (yes, that spelling is literally what the page says, bestie πŸ’…), and we’re about to get into the std::ostream_iterator::ostream_iterator constructor page. no cap, it’s giving very specific but also lowkey iconic.


πŸ“› NAME πŸ“›

std::ostream_iterator::ostream_iterator β€” std::ostream_iterator::ostream_iterator

like… the NAME line is literally that twice, separated by a hyphen. periodt. πŸŽ€


🧾 Synopsis 🧾

          ostream_iterator( ostream_type& stream, const CharT* delim ); (1)
          ostream_iterator( ostream_type& stream );                     (2)

okay so both of these construct the iterator with stream as the associated stream, and the way that happens is by storing the address of stream. main character energy fr fr ✨

  1. Uses delim as the delimiter.
  2. Uses a null pointer as the delimiter.

πŸŽ›οΈ Parameters πŸŽ›οΈ

  • stream β€” the output stream to be accessed by this iterator.
  • delim β€” the null-terminated character string to be inserted into the stream after each output.

πŸ’» Example πŸ’»

        // Run this code

        #include <algorithm>
        #include <iostream>
        #include <iterator>
        #include <numeric>

        int main()
        {
            std::ostream_iterator<char> oo{std::cout};
            std::ostream_iterator<int> i1{std::cout, ", "};
            std::fill_n(i1, 5, -1);
            *oo++ = '\n';

            std::ostream_iterator<double> i2{std::cout, "; "};
            *i2++ = 3.14;
            *i2++ = 2.71;
            *oo++ = '\n';

            std::common_iterator<std::counted_iterator<std::ostream_iterator<float>>,
                                 std::default_sentinel_t>
                first{std::counted_iterator{std::ostream_iterator<float>{std::cout,"
       ~ "}, 5}},
                last{std::default_sentinel};
            std::iota(first, last, 2.2);
            *oo++ = '\n';
        }
not me keeping that one wrapped string-literal line exactly as the page has it 😭 β€” character-for-character, bestie, no edits.

πŸ–¨οΈ Output πŸ–¨οΈ

        -1, -1, -1, -1, -1,
        3.14; 2.71;
        2.2 ~ 3.2 ~ 4.2 ~ 5.2 ~ 6.2 ~

ate. no notes. 🌈


πŸ› Defect reports πŸ›

bestie, the page says the following behavior-changing defect reports were applied retroactively to previously published C++ standards. the table columns are DR, Applied to, Behavior as published, and Correct behavior.

  • LWG 1280 β€” Applied to: C++98. Behavior as published: stream was stored directly. Correct behavior: stores its address instead.
  • P2325R3 β€” Applied to: C++20. Behavior as published: default constructor was provided as C++20. Correct behavior: removed along with the requirement iterators must be default_initializable.

source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::ostrea...eam_iterator(3) β€” okay bestie that’s the whole page, mwah πŸ’–βœ¨πŸ«Ά

πŸ“¦ where this page comes from