• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            linux&c++ R&D

            programing is a pleasure!

            How to limit instantialization?

            Title: How to limit instantialization?
            For a template class:
            template <typename T>
            struct X
            {
                static void f(){...}

            };

            Is there any way to prevent this class from being instantialized for
            different T?
            e.g:
            X<int>::f();
            X<int>::f() //ok
            ///////////////////////////////////////////////
            X<int>::f();
            X<double>::f() //compiling error
            Instantialization may be found in different source files, and X<T> may
            not have to have any instance.
            I tried some methods, but failed to prevent it in compile time.
            Can anyone help me out?
            (1)
            On 12 Mrz., 15:19, "shifan3" <shifan1234...@163.com> wrote:
            SFINAE is your friend. Your main task is to define/specialize
            your traits class MyTraits, which specifies enablement, properly.
            In this case I have used explicit specializiation for it, maybe you
            need partial specialization:
            template <bool Enable, typename T = void>
            struct EnableIf {
               typedef T Type;

            };
            template <typename T>
            struct EnableIf<false, T> {

            };
            template <typename T>
            struct MyTraits {
               static const bool value = false; // Default case: Disable

            };
            template <>
            struct MyTraits<int> {
               static const bool value = true;

            };
            template <typename T>
            struct X
            {
                 static typename
                 EnableIf<MyTraits<T>::value>::Type f(){...}

            };
            int main() {
               X<int>::f(); // OK
               X<double>::f(); // Fails

            }
            Greetings from Bremen,
            Daniel Krügler

            (2)
            template <typename T>
            struct X
            {
                static void f(){...}

            };
            template<> struct X<double>;
            or, if you don't want the incomplete type,
            template<>
            struct X<double>
            {

            };

             

             

            posted on 2007-04-30 16:44 丑石 閱讀(399) 評論(0)  編輯 收藏 引用 所屬分類: C++ problem and solution

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久亚洲国产成人精品性色| 精品久久久久久无码中文字幕| 欧美久久亚洲精品| 久久久久精品国产亚洲AV无码| 久久精品日日躁夜夜躁欧美| 久久人人妻人人爽人人爽| 精品久久久噜噜噜久久久| 伊人热人久久中文字幕| 久久国产精品无码网站| 香蕉久久av一区二区三区| 欧美精品一区二区精品久久| 四虎影视久久久免费| 国产精品美女久久久久 | 亚洲精品乱码久久久久久蜜桃图片 | 久久婷婷久久一区二区三区| 91久久精品国产91性色也| 99久久做夜夜爱天天做精品| 久久香蕉一级毛片| 少妇久久久久久久久久| 久久99精品国产麻豆婷婷| 久久91精品国产91久久麻豆| 99久久免费国产精品特黄| 国产成人精品久久一区二区三区av| 无码久久精品国产亚洲Av影片 | 久久久久无码中| 亚洲国产成人久久综合碰碰动漫3d| 久久精品国产亚洲AV香蕉| 污污内射久久一区二区欧美日韩 | 久久精品国产99国产精品 | 青青草原综合久久大伊人导航| 亚洲精品国产字幕久久不卡| 激情综合色综合久久综合| 久久国产精品成人免费| 国产精品久久久亚洲| 国产亚洲精久久久久久无码| 老色鬼久久亚洲AV综合| 亚洲狠狠婷婷综合久久蜜芽| 99精品国产99久久久久久97 | 久久亚洲国产精品一区二区| 精品久久人妻av中文字幕| 精品久久久久久无码专区|