Changeset 519


Ignore:
Timestamp:
Jun 10, 2008, 11:46:25 PM (16 years ago)
Author:
dai
Message:

ジェネリッククラスの型パラメータに値型が指定された場合、そのクラスがテンプレート展開されるように修正。ついに、下記のようなソースコードがビルド可能に!!!

#console

Dim b As System.Collections.Generic.List<Double>
b.Add( 10 )
b.Add( 20 )
Dim p = b As *Double	' ←ここがミソ!
Dim x = p[0]
Dim y = p[1]

Print x, y

System.Console.ReadLine()
Location:
trunk/ab5.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/ablib/src/Classes/System/Collections/Generic/List.ab

    r396 r519  
    2525
    2626    Sub Realloc( allocateSize As Long )
    27         items = realloc( items, allocateSize * SizeOf(VoidPtr) )
     27        items = realloc( items, allocateSize * SizeOf(T) )
    2828    End Sub
    2929
     
    4646    Function Operator[] ( index As Long ) As T
    4747        Return items[index]
     48    End Function
     49
     50    /*!
     51    @brief  ポインタ型へのキャスト
     52    @author Daisuke Yamamoto
     53    @date   2007/08/22
     54    @param  インデックス
     55    */
     56    Function Operator() As *T
     57        Return items
    4858    End Function
    4959
     
    112122    Sub Insert( index As Long, item As T )
    113123        Realloc( size + 1 )
    114         memmove( items + (index+1)*SizeOf(VoidPtr), items + index*SizeOf(VoidPtr), (size-index)*SizeOf(VoidPtr) )
     124        memmove( items + (index+1)*SizeOf(T), items + index*SizeOf(T), (size-index)*SizeOf(T) )
    115125        items[index] = item
    116126        size++
     
    140150    */
    141151    Sub RemoveAt( index As Long )
    142         memmove( items + index*SizeOf(VoidPtr), items + (index+1)*SizeOf(VoidPtr), (size-(index+1))*SizeOf(VoidPtr) )
     152        memmove( items + index*SizeOf(T), items + (index+1)*SizeOf(T), (size-(index+1))*SizeOf(T) )
    143153        Realloc( size - 1 )
    144154        size--
Note: See TracChangeset for help on using the changeset viewer.