S
Shriramana Sharma
Hello. I have this global operator I'm defining in my app for convenience:
# include <vector>
using namespace std ;
template < typename T >
vector<T> & operator << ( vector<T> & vec, const T & val ) { vec.push_back(val) ; return vec ; }
This is so I can do something like:
vector<int> A ;
A << 1 << 2 << 3 ;
My question is how often will this function be instantiated? I mean, if I had written it like:
vector<int> & operator << ( vector<int> & vec, const int & val ) { vec.push_back(val) ; return vec ; }
then there would be only one definition and this function would be called each time I use the operator. However I'm using a template to be able to usethis for a vector of any value type. So I would like to know, how many times would a particular template be instantiated? Would it also be one in accordance with the ODR or something?
# include <vector>
using namespace std ;
template < typename T >
vector<T> & operator << ( vector<T> & vec, const T & val ) { vec.push_back(val) ; return vec ; }
This is so I can do something like:
vector<int> A ;
A << 1 << 2 << 3 ;
My question is how often will this function be instantiated? I mean, if I had written it like:
vector<int> & operator << ( vector<int> & vec, const int & val ) { vec.push_back(val) ; return vec ; }
then there would be only one definition and this function would be called each time I use the operator. However I'm using a template to be able to usethis for a vector of any value type. So I would like to know, how many times would a particular template be instantiated? Would it also be one in accordance with the ODR or something?