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

                在《美國(guó)傳統(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è)想;計(jì)劃

                在范型程序設(shè)計(jì)的發(fā)源地SGI,在STL_DOC中有對(duì)什么是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,描述某個(gè)抽象型別的條件(或說需求,requirements)。concept 并
                不是一個(gè) class,也不是一個(gè)變數(shù)或是一個(gè) template 叁數(shù);C++ 語言之中沒有任何東
                西可以直接代表一個(gè)concept。然而,在每一個(gè)用到泛型程式設(shè)計(jì)方法的 C++ 程式中,
                concept 非常重要。由 concepts 所構(gòu)成的階層體系,正是 STL 的主體結(jié)構(gòu)。

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

            Feedback

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

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

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

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

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

            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ù)  更多評(píng)論   

            2007-05-31 18:03 by danielwyo

            不知道你們?cè)谡f什么, 裝得那么深?yuàn)W.
            看看AOP的定義就知道了, 其實(shí)上就是一種AOP了.

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

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

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

            2009-05-16 00:26 by 卡門
            那么品牌稱呼是否可以說為“XXXX conception"??
            久久午夜无码鲁丝片| 久久久久99精品成人片| 一本色道久久综合| 久久SE精品一区二区| 色偷偷88888欧美精品久久久| 久久综合伊人77777| 久久精品视屏| 亚洲国产成人久久综合区| 国产精品久久久久蜜芽| 伊人久久免费视频| 久久精品国产99久久丝袜| 亚洲精品99久久久久中文字幕| 久久经典免费视频| 久久青青草原亚洲av无码app| 人妻精品久久无码区| 色天使久久综合网天天 | 国产福利电影一区二区三区久久久久成人精品综合 | 久久精品国产亚洲AV大全| 国产毛片久久久久久国产毛片| 精品久久久久成人码免费动漫| 久久亚洲精品中文字幕三区| 亚洲欧美伊人久久综合一区二区| 久久影院午夜理论片无码| 国产午夜精品久久久久九九电影| 久久精品国产影库免费看 | 色综合久久中文字幕综合网| 精品久久久久久无码免费| 精品国产综合区久久久久久| 国产精品免费久久久久久久久| 国产成人精品久久一区二区三区av| 国产午夜久久影院| 一本大道久久a久久精品综合| 久久精品免费观看| 日产久久强奸免费的看| 狠狠色狠狠色综合久久| 99久久精品国产麻豆| 午夜精品久久久久9999高清| 久久偷看各类wc女厕嘘嘘| 久久久WWW成人| 国产综合久久久久| 欧美日韩精品久久久免费观看|