In the code:
-----------------------------------------------------------------------
#include <iostream>
#include <vector>
#include <utility>

// commenting out this forward declaration causes the code to fail
// under g++-14.2.0
//
// the forward declaration is not needed for g++-9.4.0
template<class T1, class T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p);

template<class N>
std::ostream& operator<<(std::ostream& os, const std::vector<N>& v) {
  os << "[";
  for(typename std::vector<N>::const_iterator i = v.begin();
      i != v.end();
      ++i) {
    if(i != v.begin() ) os << ", ";
    os << *i;
  }
  os << "]";
  return os;
}

template<class T1, class T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

using namespace std;

int main() {
  cout << pair<int,int>(3, 4) << endl;
  cout << vector<int>(3, 7) << endl;
  cout << vector<pair<int,int> >(3, pair<int,int>(3, 4)) << endl;
}

// output:
// (3,4)
// [7, 7, 7]
// [(3,4), (3,4), (3,4)]
-----------------------------------------------------------------------

the code compiles and runs under g++-9.4.0 with or without the forward declaration but g++-14.2.0 requires the forward declaration.

Did the standard change or is g++ now being more strict in following the standard.

Note that the actual code is more compicated but this is enough the show the difference.

--Sidney Marshall

Reply via email to