N
nicola
Hi,
I have a generic interface for intervals, which is defined in terms of
two global functions leftPoint() and rightPoint(). Many other
functions and operators are defined in terms of those two in a
standard way, so that, in principle, I only need to provide a
definition for leftPoint() and rightPoint() to adapt a specific data
type to an interval interface. But providing generic definitions for
the operators calls for trouble (unwanted instantiations and broken
name lookup). Is there any viable alternative to overloading all the
functions and operators for each data type (duplicating much of the
code)? Or, is there anything better than the following?
namespace A {
// Generic interface
template <typename I> point_type leftPoint(I const& i);
template <typename I> point_type rightPoint(I const& i);
template <typename I> operator<(I const& i, I const& j); // “too
generic”
// […]
// Specializations
int leftPoint(std:air<int,int>); int
rightPoint(std:air<int,int>);
float leftPoint(MyFloatInterval); float rightPoint(MyFloatInterval);
// […]
}
I have a generic interface for intervals, which is defined in terms of
two global functions leftPoint() and rightPoint(). Many other
functions and operators are defined in terms of those two in a
standard way, so that, in principle, I only need to provide a
definition for leftPoint() and rightPoint() to adapt a specific data
type to an interval interface. But providing generic definitions for
the operators calls for trouble (unwanted instantiations and broken
name lookup). Is there any viable alternative to overloading all the
functions and operators for each data type (duplicating much of the
code)? Or, is there anything better than the following?
namespace A {
// Generic interface
template <typename I> point_type leftPoint(I const& i);
template <typename I> point_type rightPoint(I const& i);
template <typename I> operator<(I const& i, I const& j); // “too
generic”
// […]
// Specializations
int leftPoint(std:air<int,int>); int
rightPoint(std:air<int,int>);
float leftPoint(MyFloatInterval); float rightPoint(MyFloatInterval);
// […]
}