Including the <iostream> header can significantly impact compile time, as it is one of the heavy standard C++ headers. As an alternative, notably for library headers, the <iosfwd> header provides only forward declaration, making it essentially free. As long as we only need to declare stream insertion and extraction functions, the <iosfwd> header is sufficient. Compiler Explorer link: https://lnkd.in/eXi9xBBa #cpp #cplusplus #coding #programming #dailybiteofcpp
Would it be more lightweight to use C stream functions with stream/file buffer pointers? Or maybe create a class with iostream-like methods and operator overrides that wrap around C stream methods.
would modules avoid the issue all together?
No way ☝🏻😱
Nifty. Thanks.
Juan Antonio Herreros Bragado
Staff Software Engineer at Woven by Toyota, Chair of SG for Compile-Time Programming, Assistant Chair for Evolution Working Group, Czech National Body in ISO/IEC JTC1 SC22 (Programming Languages) and WG21 (C++ Committee)
2yThanks for doing the teaching, not many people know about <iosfwd> header in my experience. One downside of this solution is the friend operators won't be hidden and will participate in overload set for purposes of conversions. Which can lead to unforeseen conversion. https://compiler-explorer.com/z/b36Y59dhf