From 23455639da3559a72b48ca3b967f60b90f27e264 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Thu, 26 Jul 2018 17:30:56 +0900 Subject: [PATCH] [coco] Add a static_assert for type of Child (#830) This commit limits the type of template parameter `Child` to be subclass of `DLinkedList::Node`. Signed-off-by: Hanjoung Lee --- contrib/coco/core/include/coco/ADT/DLinkedList.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/coco/core/include/coco/ADT/DLinkedList.h b/contrib/coco/core/include/coco/ADT/DLinkedList.h index ea46633..d2af781 100644 --- a/contrib/coco/core/include/coco/ADT/DLinkedList.h +++ b/contrib/coco/core/include/coco/ADT/DLinkedList.h @@ -4,6 +4,7 @@ #include "coco/ADT/PtrLink.h" #include +#include namespace coco { @@ -134,6 +135,8 @@ template struct DLinkedList public: Node(const PtrLink *link) : _link{link} { + static_assert(std::is_base_of::value, "Type `Child` must be subclass of `Node`."); + _prev = nullptr; _next = nullptr; } @@ -160,7 +163,6 @@ template struct DLinkedList assert(_prev == nullptr); assert(_next == nullptr); - // REQUIRE Child should inheir Node class auto curr = reinterpret_cast(this); // Update the link of the current node @@ -188,7 +190,6 @@ template struct DLinkedList assert(_prev == nullptr); assert(_next == nullptr); - // REQUIRE Child should inherit Node class auto curr = reinterpret_cast(this); // Update the link of the current node @@ -211,7 +212,6 @@ template struct DLinkedList public: void detach(void) { - // REQUIRE Child SHOULD inherit Node class auto curr = reinterpret_cast(this); // Update parent-child relation -- 2.7.4