C ++ 2003、§17.4.3.1/ 1:「プログラムは任意の標準ライブラリテンプレートのテンプレート特殊化を名前空間stdに追加できます。宣言がユーザーに依存しない限り、標準ライブラリテンプレートのそのような特殊化(完全または部分的)は未定義の動作になります-外部リンケージの定義された名前。スペシャライゼーションが元のテンプレートの標準ライブラリ要件を満たさない場合。」
そのため、ユーザー定義型に依存し、元のテンプレートの要件を満たしている限り、ライブラリテンプレートを特殊化し、名前空間に特殊化することができます。std
編集した質問にあるコードは、(おそらく)外部リンクを持つユーザー定義名の特殊化のようです。したがって、その部分に問題はないはずです。
それはあなたの専門分野が元のテンプレートの要件を満たすという要件だけを残します。あなたのタイプの場合、これのほとんどはおそらく些細なことに国境を接します。明らかではないかもしれない唯一の部分は、テンプレートだけでなく、テンプレート全体に特殊化を提供する必要があるように見えることですnumeric_limits::max()
。つまり、次のようなことを行う必要があります(128ビットの符号なし整数型の例は球場にあるはずです):
namespace std {
template <>
class numeric_limits<my_integer> {
public:
static const bool is_specialized = true;
static T min() throw() { return 0;
static T max() throw() { return /* 2^128-1 */; } // ***
static const int digits = 128;
static const int digits10 = 38;
static const bool is_signed = false;
static const bool is_integer = true;
static const bool is_exact = true;
static const int radix = 2;
static T epsilon() throw() { return 0; }
static T round_error() throw() { return 0; }
static const int min_exponent = 0;
static const int min_exponent10 = 0;
static const int max_exponent = 0;
static const int max_exponent10 = 0;
static const bool has_infinity = false;
static const bool has_quiet_NaN = false;
static const bool has_signaling_NaN = false;
static const float_denorm_style has_denorm = denorm_absent;
static const bool has_denorm_loss = false;
static T infinity() throw() { return 0; }
static T quiet_NaN() throw() { return 0; }
static T signaling_NaN() throw() { return 0; }
static T denorm_min() throw() { return 0; }
static const bool is_iec559 = false;
static const bool is_bounded = true;
static const bool is_modulo = true;
static const bool traps = false;
static const bool tinyness_before = false;
static const float_round_style round_style = round_toward_zero;
};
}
それらのかなりの数は実際にはFP型用であり、整数型にとって意味がある必要はありません。まだ実装する必要があると思います。