vendredi 31 juillet 2020

Is there a way to change Default Nontype Template Parameters when overloading `std::ostream` operator?

#include <iostream>

struct Foo {
  template <int bias = 5>
  void print() {
    std::cout << bias << std::endl;
  }
};

template <int bias = 5>
std::ostream &operator<<(std::ostream &os, const Foo &foo) {
  return os << bias;
}

int main() {
  Foo a;
  a.print();
  a.print<>();
  a.print<1>();
  std::cout << a << std::endl;
  return 0;
}

By showing this code, I mean, despite the terrible implementation, is there a way to change the default parameter 5 while using std::cout and keeping the struct unchanged?

Aucun commentaire:

Enregistrer un commentaire