[英]Specialize function template by static value in class of template parameter
我有函數op
,我想專門針對模板參數PROCESSOR::DIMENSION = 2
所有情況進行處理。 這完全有可能嗎?或者我如何能實現類似的目標?
// How to specialize this for all PROCESSOR with DIMENSION = 2?
template <class PROCESSOR>
void op(Node<PROCESSOR>& node){
}
// this is an example for template parameter PROCESSOR
template <int DIM>
class CPU
{
public:
static int DIMENSION = DIM;
};
(如果您懷疑有XY問題,那可能是對的。我在這里有一個相對復雜的設計任務,並且我正在評估如何實現的不同想法。其中一個導致出現上述X。特別是,我嘗試避免多態指針,因為它們會阻止編譯器內聯,我們正在討論高性能應用程序的非常小的代碼段。)
像這樣。 請注意,您不能部分專門化功能:
template <class PROCESSOR, int D = PROCESSOR::DIM>
struct op
{
void operator()(...);
};
template <class PROCESSOR>
struct op<PROCESSOR, 2>
{
void operator()(...);
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.