class A {};
class B {};
class C {};
class D {};
//A+B , A+C, B+C , A+D, D+C namely all of these combinations will be possible just one functions
1 に答える
2
template <typename T, typename U>
void foo(const T& pX, const U& pY)
{
// do stuff
}
T
これは、とのさまざまな組み合わせごとに新しい関数を作成するため、それ自体は望んでいるものではありませんが、U
1 つの関数テンプレートです。
T
これにより、 とU
が同じになることが禁止されます。
template <bool> struct static_assert {};
template <> struct<true> static_assert {};
#define STATIC_ASSERT(pValue) static_assert<(pValue)>()
// ...
template <typename T, typename U>
struct is_different
{
static const bool value = true;
};
template <typename T>
struct is_different<T, T>
{
static const bool value = false;
};
// ...
template <typename T, typename U>
void foo(const T& pX, const U& pY)
{
STATIC_ASSERT(is_different<T, U>::value);
// do stuff
}
于 2010-06-05T22:10:43.273 に答える