xo-object2: streamline DList::list use
This commit is contained in:
parent
ce32d59bc3
commit
8f1361763e
3 changed files with 35 additions and 2 deletions
|
|
@ -34,6 +34,17 @@ namespace xo {
|
|||
obj<AGCObject> car,
|
||||
obj<ACdrFacet,DList> cdr);
|
||||
|
||||
/** list with one element @p e1, allocated from @p mm **/
|
||||
template <typename AListFacet = AGCObject>
|
||||
static obj<AListFacet,DList> list(obj<AAllocator> mm,
|
||||
obj<AGCObject> e1);
|
||||
|
||||
/** list with two element @p e1, @p e2, allocated from @p mm **/
|
||||
template <typename AListFacet = AGCObject>
|
||||
static obj<AListFacet,DList> list(obj<AAllocator> mm,
|
||||
obj<AGCObject> e1,
|
||||
obj<AGCObject> e2);
|
||||
|
||||
/** sentinel for null list **/
|
||||
static DList * _nil();
|
||||
|
||||
|
|
@ -45,6 +56,7 @@ namespace xo {
|
|||
obj<AGCObject> car,
|
||||
DList * cdr);
|
||||
|
||||
#ifdef OBSOLETE
|
||||
/** list with one element @p h1, allocated from @p mm **/
|
||||
static DList * list(obj<AAllocator> mm,
|
||||
obj<AGCObject> h1);
|
||||
|
|
@ -52,6 +64,7 @@ namespace xo {
|
|||
static DList * list(obj<AAllocator> mm,
|
||||
obj<AGCObject> h1,
|
||||
obj<AGCObject> h2);
|
||||
#endif
|
||||
|
||||
/** DList length is at least 1 **/
|
||||
bool is_empty() const noexcept;
|
||||
|
|
@ -87,6 +100,23 @@ namespace xo {
|
|||
return obj<AConsFacet,DList>(DList::_cons(mm, car, cdr.data()));
|
||||
}
|
||||
|
||||
template <typename AListFacet>
|
||||
obj<AListFacet,DList>
|
||||
DList::list(obj<AAllocator> mm,
|
||||
obj<AGCObject> e1)
|
||||
{
|
||||
return cons(mm, e1, nil());
|
||||
}
|
||||
|
||||
template <typename AListFacet>
|
||||
obj<AListFacet,DList>
|
||||
DList::list(obj<AAllocator> mm,
|
||||
obj<AGCObject> e1,
|
||||
obj<AGCObject> e2)
|
||||
{
|
||||
return cons(mm, e1, list(mm, e2));
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ namespace xo {
|
|||
return new (mem) DList(car, cdr);
|
||||
}
|
||||
|
||||
#ifdef OBSOLETE
|
||||
DList *
|
||||
DList::list(obj<AAllocator> mm,
|
||||
obj<AGCObject> h1)
|
||||
|
|
@ -52,6 +53,7 @@ namespace xo {
|
|||
|
||||
return new (mem) DList(h1, DList::list(mm, h2));
|
||||
}
|
||||
#endif
|
||||
|
||||
bool
|
||||
DList::is_empty() const noexcept
|
||||
|
|
|
|||
|
|
@ -171,8 +171,9 @@ namespace ut {
|
|||
c_o.add_gc_root(&x0_o);
|
||||
REQUIRE(to_0->allocated() == sizeof(AllocHeader) + sizeof(DFloat));
|
||||
|
||||
DList * l0 = DList::list(gc_o, x0_o);
|
||||
auto l0_o = with_facet<AGCObject>::mkobj(l0);
|
||||
//DList * l0 = DList::list(gc_o, x0_o);
|
||||
//auto l0_o = with_facet<AGCObject>::mkobj(l0);
|
||||
auto l0_o = DList::list(gc_o, x0_o);
|
||||
c_o.add_gc_root(&l0_o);
|
||||
REQUIRE(to_0->allocated() == (sizeof(AllocHeader) + sizeof(DFloat)
|
||||
+ sizeof(AllocHeader) + sizeof(DList)));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue