On Fri, 12 Jul 2024 at 20:08, Dalbey, Keith <kdal...@sandia.gov> wrote:
>
> The means by which this FIX was implemented caused OTHER problems
>
> template <typename F, typename S>
> std::ostream& operator<<(std::ostream& os, const std::pair<F,S>& pr)
> {
>         os << "(" << pr.first << ", " << pr.second << ")";
>         return os;
> }
>
> Will only work for CONCRETE classes that take the place of "F" and "S" IFF 
> each of their concrete operator<< 's is FORWARD DECLARED ahead of the above 
> template, so primitives like int and double should still work,  but if you 
> include this file in a header file that contains a concrete class that you 
> define an operator<< for, and then use in another file, you're SOL.
>
> If you mix that with templated operator<< for vectors and std::shared_ptr  
> then there's a chicken and the egg problem for which STL templated operator<< 
> gets declared first/ but you can work around this by FORWARD declaring all of 
> your operator<< (including the concrete and templated ones) before 
> **Defining** the STL templated operator<< 's, but that means the header file 
> containing the STL templated operator<< 's can never be included in another 
> header file and it can only be included as *the absolute last header file* in 
> a .cpp file (so that all the concrete operator<< get declared before them, 
> and you may still need to forward declare some of the contents of the .cpp 
> file ahead of including this header file)
>
> But really a header file that can't be included in other header files and can 
> only be included as the absolute last header file in a .cpp file is a 
> unreasonable set of hoops to jump through to get TEMPLATED operator<< 's to 
> work, which should just work BECAUSE THEY'RE TEMPLATES

You keep insisting that templates should mean something that isn't
what they mean in C++, and isn't how they work in other compilers.

Maybe you should try writing correct C++ instead?

Reply via email to