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

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            一本久道久久综合狠狠爱| 国产午夜精品久久久久九九电影| 精品久久久久中文字幕一区| 一本大道久久a久久精品综合| 久久黄色视频| 香港aa三级久久三级| 久久精品一区二区三区AV| 少妇久久久久久被弄到高潮| 亚洲伊人久久成综合人影院| 久久人人爽人人爽AV片| 国产女人aaa级久久久级| 久久亚洲私人国产精品| 久久国产欧美日韩精品| 久久午夜羞羞影院免费观看| 国产精品久久久久久搜索| 国产成人久久久精品二区三区| 亚洲精品综合久久| 99精品国产在热久久无毒不卡| 一本色道久久综合| 久久99精品免费一区二区| 久久高清一级毛片| 久久99精品久久久久久不卡 | 久久午夜伦鲁片免费无码| 无码国内精品久久综合88| 伊人久久大香线蕉综合5g| 99久久99久久精品国产片| 久久国产影院| 欧美一区二区三区久久综合| 久久人人爽人人爽人人片AV不| 久久综合亚洲色HEZYO社区| 一本色道久久99一综合| 久久久久久免费一区二区三区| 久久er国产精品免费观看2| 国产69精品久久久久99尤物| 久久久WWW成人| 国产亚洲精午夜久久久久久| 中文字幕精品无码久久久久久3D日动漫 | 久久精品国产清自在天天线| 亚洲国产高清精品线久久 | 久久久久亚洲av成人无码电影| 色欲久久久天天天综合网|