• <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 丑石 閱讀(392) 評論(0)  編輯 收藏 引用 所屬分類: C++ problem and solution

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            精品久久久久久无码中文野结衣| 久久无码高潮喷水| 精品久久久久久久中文字幕| 久久久国产精品网站| 久久人人爽人爽人人爽av| 精品伊人久久久| …久久精品99久久香蕉国产| 青青草原综合久久大伊人导航| 久久久久久久精品成人热色戒| 国产成人久久激情91| 久久这里的只有是精品23| 久久99精品久久久久子伦| 久久久久亚洲精品天堂久久久久久| 久久精品国产亚洲AV不卡| 99久久精品免费看国产免费| 亚洲av日韩精品久久久久久a| 国产A级毛片久久久精品毛片| 国内精品伊人久久久久777| 99久久人人爽亚洲精品美女| 麻豆AV一区二区三区久久| 欧美精品丝袜久久久中文字幕 | 2021久久国自产拍精品| 一本久久综合亚洲鲁鲁五月天| 88久久精品无码一区二区毛片| 成人久久免费网站| 久久精品国产亚洲AV香蕉| 青春久久| 99久久免费国产精品特黄| 久久久久国产视频电影| Xx性欧美肥妇精品久久久久久| 久久久久久久久久久久中文字幕| 国产欧美久久久精品影院| 污污内射久久一区二区欧美日韩 | 亚洲熟妇无码另类久久久| 久久综合九色综合欧美就去吻| 久久国产乱子伦精品免费午夜| 亚洲国产精品久久66| 国产精品熟女福利久久AV| 精品国产婷婷久久久| 久久综合给合综合久久| 欧美精品九九99久久在观看|