M
Marc
When we implement a pair or a tuple, and one of the objects is empty,
we usually implement it with private inheritance to benefit from the
empty base class optimization:
class pair {
Empty first;
Real second;
public:
// ... some accessors
};
becomes:
class pair : private Empty {
Real second;
public:
// ... some accessors
};
Now in a templated version, we don't know in advance if the first type
will be empty (let us ignore the possibility that the second type may
be empty for now), so we dispatch based on is_empty<First>::value to
use the second implementation if it is empty and the first otherwise .
At least that's what I have seen in every implementation so far.
However, it seems to me that the second implementation should work
whether the type is empty or not, and one implementation is better
than two.
I am probably missing something here, could you tell me what are the
advantages of the first version when the type is not empty?
we usually implement it with private inheritance to benefit from the
empty base class optimization:
class pair {
Empty first;
Real second;
public:
// ... some accessors
};
becomes:
class pair : private Empty {
Real second;
public:
// ... some accessors
};
Now in a templated version, we don't know in advance if the first type
will be empty (let us ignore the possibility that the second type may
be empty for now), so we dispatch based on is_empty<First>::value to
use the second implementation if it is empty and the first otherwise .
At least that's what I have seen in every implementation so far.
However, it seems to me that the second implementation should work
whether the type is empty or not, and one implementation is better
than two.
I am probably missing something here, could you tell me what are the
advantages of the first version when the type is not empty?