• <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高清漫画| 亚洲人成电影网站久久| 久久亚洲av无码精品浪潮| 亚洲精品午夜国产va久久| 久久国产亚洲精品麻豆| 伊人久久大香线蕉精品不卡| 亚洲欧美日韩中文久久| 久久九九免费高清视频| 老色鬼久久亚洲AV综合| 久久国产热这里只有精品| 国色天香久久久久久久小说 | 久久精品草草草| 伊人久久综合精品无码AV专区| 久久精品国产亚洲AV大全| 久久久久亚洲av成人网人人软件| 久久丫精品国产亚洲av不卡| 香蕉久久AⅤ一区二区三区| 久久97精品久久久久久久不卡| 久久婷婷是五月综合色狠狠| 精品无码人妻久久久久久| 九九久久99综合一区二区| 亚洲国产精品无码久久| 久久久精品国产免大香伊| 精品久久人人做人人爽综合| 青青草国产成人久久91网| 精品久久一区二区| 久久精品中文字幕有码| 久久人人爽人爽人人爽av| 亚洲午夜久久久久妓女影院| 久久人人爽人人爽人人片av麻烦| 亚洲日韩中文无码久久| 久久综合久久综合九色| 久久婷婷五月综合97色直播| 亚洲日韩中文无码久久| 热RE99久久精品国产66热| 久久精品99久久香蕉国产色戒 | 国产精品午夜久久| 成人综合久久精品色婷婷| 久久最近最新中文字幕大全 |