-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList.cpp
38 lines (30 loc) · 838 Bytes
/
List.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// List.cpp
// CppAxiomsExample
//
// Created by Erik M. Buck on 3/31/22.
//
#include "List.h"
List::List(it_t begin, it_t end)
: m_contents(std::vector<int>(begin, end))
{
}
List::List(const List& other, int element)
: m_contents(
std::vector<int>(other.m_contents.begin(), other.m_contents.end()))
{
m_contents.push_back(element);
}
int car(const List& l) { return l.m_contents.back(); }
List cdr(const List& l)
{
return List(l.m_contents.begin(), l.m_contents.end() - 1);
}
List cons(const List& l, int element) { return List(l, element); }
int first(const List& l) { return car(l); }
List rest(const List& l) { return cdr(l); }
List append(const List& l, int element) { return cons(l, element); }
bool operator==(const List& lhs, const List& rhs)
{
return lhs.m_contents == rhs.m_contents;
}