R
Rui Maciel
Let's say that we have a host class foo which has part of it's interface implemented through a
policy class of type BarPolicy, which could be anyone between BarPolicy1 and BarPolicyN:
<code>
template<typename scalar>
class BarPolicy1
{
public:
BarPolicy() {};
~BarPolicy() {};
scalar value(const size_t a, const size_t b);
};
// snipped: other BarPolicy classes
template<typename scalar, template<typename> class BarPolicy>
class Foo
: public BarPolicy<scalar>
{
public:
Foo() {};
~Foo() {};
scalar value(const size_t a, const size_t b) {return 1; };
};
</code>
Now, I intend to overload operator<< to output the contents of class Foo to the standard output
streams, no matter what policy class has been used in assembling a host class Foo and no matter what
type has been passed as Foo's scalar. The thing is, overloading operator<< considering only the
case where Foo is implemented with a specific policy (for example, BarPolicy1) is a trivial task to
accomplish. Yet, I'm not getting any luck in overloading operator<< so that it accepts any generic
Foo class, independent of what policy has been adopted.
So, can anyone help? Is it possible to declare such an operator? If so, can anyone provide with an
example?
Thanks in advance,
Rui Maciel
policy class of type BarPolicy, which could be anyone between BarPolicy1 and BarPolicyN:
<code>
template<typename scalar>
class BarPolicy1
{
public:
BarPolicy() {};
~BarPolicy() {};
scalar value(const size_t a, const size_t b);
};
// snipped: other BarPolicy classes
template<typename scalar, template<typename> class BarPolicy>
class Foo
: public BarPolicy<scalar>
{
public:
Foo() {};
~Foo() {};
scalar value(const size_t a, const size_t b) {return 1; };
};
</code>
Now, I intend to overload operator<< to output the contents of class Foo to the standard output
streams, no matter what policy class has been used in assembling a host class Foo and no matter what
type has been passed as Foo's scalar. The thing is, overloading operator<< considering only the
case where Foo is implemented with a specific policy (for example, BarPolicy1) is a trivial task to
accomplish. Yet, I'm not getting any luck in overloading operator<< so that it accepts any generic
Foo class, independent of what policy has been adopted.
So, can anyone help? Is it possible to declare such an operator? If so, can anyone provide with an
example?
Thanks in advance,
Rui Maciel