関数 (または少なくともクラス) を特殊化して、定数 (コンパイル時!) 整数と他のすべての引数を選択することは可能ですか? その場合は、特定の定数値のみに特化 (enable_if) するとよいでしょう。
以下の例では、これは 3 つの「var」ではなく、出力「var」、「const」、および「var」を意味します。
#include <type_traits>
#include <iostream>
using namespace std;
struct test
{
template <typename T>
test& operator=(const T& var) { cout << "var" << endl; return *this; }
template <int n> // enable_if< n == 0 >
test& operator=(int x) { cout << "const" << endl; return *this; }
};
int main()
{
test x;
x = "x";
x = 1;
int y = 55;
x = y;
return 0;
}
更新: コードを編集して、コンパイル時に一定でなければならないことを強調しました。