std::ostrea...eam_iterator(3)
π 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 β¨
- Uses
delimas the delimiter. - 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:streamwas 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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms