• <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>
            posts - 28, comments - 179, trackbacks - 0, articles - 1
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            什么是concept

            Posted on 2007-05-31 14:45 chemz 閱讀(2184) 評論(6)  編輯 收藏 引用 所屬分類: C++
                                              什么是concept
                在范型程序設(shè)計領(lǐng)域有一個必須要掌握的名詞“concept”,中文翻譯叫做“概念”,這個
            翻譯僅僅是一個concept英文的直譯,并沒有包含范型程序設(shè)計中concept的特定含義,要想
            真正的進(jìn)入到范型程序設(shè)計領(lǐng)域,理解范型設(shè)計的思想,首先必須完全弄明白什么是concept?

                在《美國傳統(tǒng)詞典[雙解]》中,concept這一名詞被解釋為:
                1. A general idea derived or inferred from specific instances or occurrences.
                   概念:從特定情形或事件中得到或推斷出的一般性想法
                2. Something formed in the mind; a thought or notion.See Synonyms at idea.
                   想法:在腦海中形成的想法;思想或觀念參見 idea
                3. Usage Problem A scheme; a plan.
                   設(shè)想;計劃

                在范型程序設(shè)計的發(fā)源地SGI,在STL_DOC中有對什么是concept的專門的描述:
                “One very important question to ask about any template function, not just
                about STL algorithms, is what the set of types is that may correctly be
                substituted for the formal template parameters. Clearly, for example,
                int* or double* may be substituted for find's formal template parameter
                InputIterator. Equally clearly, int  or double may not: find uses the
                expression *first, and the dereference operator makes no sense for an
                object of type int  or of type double. The basic answer, then, is that
                find  implicitly defines a set of requirements on types, and that it may
                be instantiated with any type that satisfies those requirements. Whatever
                type is substituted for InputIterator must provide certain operations: it
                must be possible to compare two objects of that type for equality, it must
                be possible to increment an object of that type, it must be possible to
                dereference an object of that type to obtain the object that it points to,
                and so on.
                Find isn't the only STL algorithm that has such a set of requirements; the
                arguments to for_each and count, and other algorithms, must satisfy the same
                requirements. These requirements are sufficiently important that we give them
                a name: we call such a set of type requirements a concept, and we call this
                particular concept Input Iterator. We say that a type conforms to a concept,
                or that it is a model of a concept, if it satisfies all of those requirements.
                We say that int* is a model of Input Iterator because int* provides all of the
                operations that are specified by the Input Iterator requirements.
                Concepts are not a part of the C++ language; there is no way to declare a
                concept in a program, or to declare that a particular type is a model of a
                concept. Nevertheless, concepts are an extremely important part of the STL.
                Using concepts makes it possible to write programs that cleanly separate
                interface from implementation: the author of find only has to consider the
                interface specified by the concept Input Iterator, rather than the
                implementation of every possible type that conforms to that concept. Similarly,
                if you want to use find, you need only to ensure that the arguments you pass
                to it are models of Input Iterator. This is the reason why find and reverse
                can be used with lists, vectors, C arrays, and many other types: programming
                in terms of concepts, rather than in terms of specific types, makes it possible
                to reuse software components and to combine components together. ”
                
                侯捷在《Genericity/STL 大系》一文中將concept解釋為:(此處和SGI的說法吻合)
                “所謂 concept,描述某個抽象型別的條件(或說需求,requirements)。concept 并
                不是一個 class,也不是一個變數(shù)或是一個 template 叁數(shù);C++ 語言之中沒有任何東
                西可以直接代表一個concept。然而,在每一個用到泛型程式設(shè)計方法的 C++ 程式中,
                concept 非常重要。由 concepts 所構(gòu)成的階層體系,正是 STL 的主體結(jié)構(gòu)。

                當(dāng)某個型別滿足某個 concept 的所有條件,我們便說此型別是該 conecpt 的一個model。
                concept 可被視為一組型別條件。如果型別 T 是 concept C 的一個 model,那麼 T 就
                一定滿足 C 的所有條件。因此,concept 亦可被視為是一組型別。如果型別 T 是
                concept C 的一個 model,我們便可說 T 隸屬於「C 所表現(xiàn)的一組型別」”
               
                由上面的三種不同角度的解釋可以看出來,concept實際上應(yīng)該是一個人在認(rèn)識一種事物
            或現(xiàn)象的過程中總結(jié)或抽象出來的一種思想和設(shè)計,而由于人類在認(rèn)知事物、現(xiàn)象和世界時
            均帶有自身的約束和局限,那么就決定了總結(jié)或抽象出來的思想和設(shè)計都具有一定的約束和
            局限,或者叫做具有一定的邊界(范圍)。那么在人們利用這些思想或設(shè)計重新審視一種
            事物或現(xiàn)象時,就會在這種思想和設(shè)計的邊界之內(nèi)來進(jìn)行判斷,在這個范圍內(nèi)的我們稱之為
            符合這種概念,那么如何判斷一種事物或現(xiàn)象是否符合某個概念呢?一般情況下必須在這個
            concept下形成特殊的判斷條件,這些條件組合起來完成了一種concept和另外一種concept
            之間的區(qū)別,也就是條件的集合稱為了判斷一種事物或現(xiàn)象是否歸屬于某一個concept的依據(jù)。
            當(dāng)然,不同的concept之間可能會有交集,但絕對不會完全重合。
                上面是一種一般性的極度抽象的解釋concept的方法,在將這種解釋應(yīng)用到某一個實際的
            真實環(huán)境或領(lǐng)域時應(yīng)該是如何的呢?我們需要給這個concept指定一個名稱,用于表示這個
            concept,同時我們還必須確定這個用于判斷一種事物或現(xiàn)象是否歸屬于這個concept的條件
            ,進(jìn)而形成concept的判斷邊界(范圍,集合)。那么在范型程序設(shè)計中的concept就非常好
            理解了,比如:Iterator這樣的一種concept,同樣是在人們的程序設(shè)計過程中為了完成對
            容器對象中的元素進(jìn)行訪問,而抽象和總結(jié)出來的處理類似問題域的一種思想或設(shè)計,那么
            經(jīng)過更進(jìn)一步的設(shè)計和構(gòu)想,就會逐漸的將什么才能夠算得上是一個iterator的判斷依據(jù)
            確定下來,形成Iterator這一concept的邊界,也就是他形成了一些用于鑒別一個實例是否
            歸屬于一個concept范疇的條件集合(約束集),在軟件中這實際上就是一個實例必須具備
            concept所定義的接口形式和語義(包括編譯時和運(yùn)行時),在Iterator概念中就必須明確
            的要求一個實例必須提供類似于++、--、*、==、!=等等這樣的接口形式和每一種接口所代
            表的語義,要注意形式和語義是缺一不可的,必須嚴(yán)格的符合,否則就不能夠算是符合某一
            個concept。
                其實concept就是這些東西,上面的解釋過于形式化,不太好理解。因為不是每一個都能
            很好的僅僅通過形式化的定義理解一個concept的形成條件、最初的問題域、和提出者的思想
            的(也就和一個代數(shù)公式一樣,必須要在他所形成和適用的環(huán)境中才能夠較容易的理解),這
            樣一來,人們會在concept形式化的描述中添加一些該concept最初的問題域的描述、形成時
            提出者的思想和初衷想法等,以幫助理解這個concept,所以就形成了STL_DOC和侯捷等其他人
            的有關(guān)concept就是一組需求的解釋,其實STL_DOC的解釋更為全面和準(zhǔn)確。
                

            Feedback

            # re: 什么是concept  回復(fù)  更多評論   

            2007-05-31 14:52 by longshanks
            現(xiàn)在對concept有什么正式的譯法嗎?

            # re: 什么是concept[未登錄]  回復(fù)  更多評論   

            2007-05-31 16:14 by Joe
            那The Blocks Problem 是什么意思呢?

            # re: 什么是concept  回復(fù)  更多評論   

            2007-05-31 17:28 by vivilood
            Concept is what it looks like. Iterator is iterator since it looks like a iterator.

            # re: 什么是concept  回復(fù)  更多評論   

            2007-05-31 18:03 by danielwyo

            不知道你們在說什么, 裝得那么深奧.
            看看AOP的定義就知道了, 其實上就是一種AOP了.

            # re: 什么是concept  回復(fù)  更多評論   

            2007-06-04 14:14 by 看圖軟件
            概念讓我想起股市的題材,呵呵

            # re: 什么是concept  回復(fù)  更多評論   

            2009-05-16 00:26 by 卡門
            那么品牌稱呼是否可以說為“XXXX conception"??
            国产农村妇女毛片精品久久| 亚洲中文久久精品无码| 成人久久精品一区二区三区| 久久亚洲日韩精品一区二区三区| 久久综合久久久| 精品久久久久久无码不卡| 久久久久高潮毛片免费全部播放 | 久久精品人人做人人爽电影蜜月 | 99久久国产亚洲综合精品| 亚洲色欲久久久综合网| 国产福利电影一区二区三区久久久久成人精品综合 | 久久精品国产半推半就| 久久中文精品无码中文字幕| 久久综合狠狠综合久久| 色综合久久久久综合99| 久久久久国产一级毛片高清版| 中文字幕无码av激情不卡久久| 亚洲乱亚洲乱淫久久| 久久99精品久久久久婷婷| 久久久久亚洲av综合波多野结衣| 色综合久久中文色婷婷| 精品综合久久久久久97超人| 精品久久亚洲中文无码| 欧美激情精品久久久久久久九九九| 成人国内精品久久久久影院| 亚洲中文精品久久久久久不卡| 久久亚洲欧洲国产综合| 狠狠人妻久久久久久综合蜜桃| 国产一久久香蕉国产线看观看| 人妻无码αv中文字幕久久琪琪布| 色播久久人人爽人人爽人人片aV| 国产福利电影一区二区三区久久老子无码午夜伦不 | 亚洲午夜精品久久久久久浪潮 | 国产精品久久久久久久人人看| 久久婷婷人人澡人人| 久久综合九色综合久99| 欧美精品福利视频一区二区三区久久久精品 | 理论片午午伦夜理片久久| 久久99精品久久久久久水蜜桃| 久久www免费人成精品香蕉| 久久精品无码一区二区三区免费|