1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef SANDBOX_LINUX_BPF_DSL_CONS_H_
6 #define SANDBOX_LINUX_BPF_DSL_CONS_H_
8 #include "base/memory/ref_counted.h"
9 #include "sandbox/sandbox_export.h"
13 // Cons provides an immutable linked list abstraction as commonly
14 // provided in functional programming languages like Lisp or Haskell.
16 class Cons
: public base::RefCounted
<Cons
<T
> > {
18 // List provides an abstraction for referencing a list of zero or
20 typedef scoped_refptr
<const Cons
<T
> > List
;
22 // Return this node's head element.
23 const T
& head() const { return head_
; }
25 // Return this node's tail element.
26 List
tail() const { return tail_
; }
28 // Construct a new List using |head| and |tail|.
29 static List
Make(const T
& head
, List tail
) {
30 return make_scoped_refptr(new const Cons
<T
>(head
, tail
));
34 Cons(const T
& head
, List tail
) : head_(head
), tail_(tail
) {}
40 friend class base::RefCounted
<Cons
<T
> >;
41 DISALLOW_COPY_AND_ASSIGN(Cons
);
44 } // namespace sandbox
46 #endif // SANDBOX_LINUX_BPF_DSL_CONS_H_